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

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


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

【热门文章】
【热门文章】