开发者

CouchDb automatic timestamps

开发者 https://www.devze.com 2023-01-03 09:56 出处:网络
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

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 "开发者_Go百科+doc.timestamp;
      return [doc, message];
    }
  }
}


The 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消