nodeJS怎么在mongodb插入数据的时候增加插入时的时间戳?

var data = {    
                 _id: reqId,
                 userId: userId,
                 time_begin: time_begin,
                 time_end: time_end,
                 time_save: **时间戳**
           }
                db.collection('sche_'+userId).insertOne(data).then(function(r) {
                    test.equal(1, r.insertedCount);
                    res.json(data);
                    db.close();
                    console.log('成功');
                })

看到这个,可是完全不懂怎么弄啊. 求大神
http://mongodb.github.io/node-mongodb-native/2.1/api/Timestamp.html

阅读 5.7k
1 个回答

时间戳在程序中获取,不要用数据库生成。由于网络延迟等原因,数据库生成的时间可能会比用户界面点保存的时间延迟,这种情况下保存的数据就是错的了。在程序中生成保存时间就很简单了吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题