Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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];
    }
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
338 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...