CouchDb自动时间戳 [英] CouchDb automatic timestamps

查看:72
本文介绍了CouchDb自动时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CouchDB实现消息应用程序。我想将时间戳记应用于每封邮件。我发现一些参考资料表明我应该为此使用文档更新处理程序。就地更新似乎是正确的事情。但是我将从哪里获得时间戳记?

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];
    }
  }
}


推荐答案

答案是使用javascript的日期函数。

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];
    }
  }
}

不幸的是,将此更新更新为下一个问题是来自jcouchdb的触发器。

Unfortunately, getting this update to trigger from jcouchdb is the next problem.

这篇关于CouchDb自动时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆