admin管理员组文章数量:1325136
I'm implementing a message application using CouchDB. I want to apply timestamps to each message. I found some references indicating that I should use document update handlers for this. In place updates seem like the right thing. But where would I get a timestamp from? Is it in the req object somewhere?
{
updates: {
"in-place" : function(doc, req) {
doc.timestamp = "???";
var message = "set timestamp to "+doc.timestamp;
return [doc, message];
}
}
}
I'm implementing a message application using CouchDB. I want to apply timestamps to each message. I found some references indicating that I should use document update handlers for this. In place updates seem like the right thing. But where would I get a timestamp from? Is it in the req object somewhere?
{
updates: {
"in-place" : function(doc, req) {
doc.timestamp = "???";
var message = "set timestamp to "+doc.timestamp;
return [doc, message];
}
}
}
Share
Improve this question
asked Jun 9, 2010 at 21:03
SorcyCatSorcyCat
1,21610 silver badges19 bronze badges
1
- stackoverflow./questions/4812235/… – abernier Commented Nov 11, 2012 at 15:05
1 Answer
Reset to default 7The answer is to use javascript's date functions.
{
updates: {
"in-place" : function(doc, req) {
doc.timestamp = new Date().getTime();
var message = "set timestamp to "+doc.timestamp;
return [doc, message];
}
}
}
Unfortunately, getting this update to trigger from jcouchdb is the next problem.
本文标签: javascriptCouchDb automatic timestampsStack Overflow
版权声明:本文标题:javascript - CouchDb automatic timestamps - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742177749a2427891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论