Inserting the current datetime in mongodb

后端 未结 1 608
独厮守ぢ
独厮守ぢ 2021-02-04 02:53

I have been having trouble inserting an actual datetime object in mongodb using the mongojs driver for nodejs. Any help?

var currentdate = new Date(); 
var date         


        
1条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 03:47

    You do not need to do all this manual date creation.

    db.test.update({
        conversation: conv
    }, { 
        $push:{ messages: {
            message: message,
            pseudo: name,
            current_date: new Date()
        } }
    }, {
        upsert: true
    });
    

    would do the job.

    Also keep in mind, that in Mongo 2.6 among many other features you can use $currentDate which might be handy.

    0 讨论(0)
提交回复
热议问题