Sign In Register

How can we help you today?

Start a new topic
Answered

How to insert date into a document

Hi guys,


How do I go about inserting and updating a document's field with the current time? Something like: {time:now()}.


Best Answer

You can use new Date() to get the current date / time


var now = new Date();


You can then use this in your update document


{"time" : now}


Gabriel



Answer

You can use new Date() to get the current date / time


var now = new Date();


You can then use this in your update document


{"time" : now}


Gabriel


how does one insert a date into a meta collection?


i've tried on the NoSQL Explorer to insert the following:

{"date":new Date("2014-12-11T14:12:00Z")}

{"date":ISODate("2014-12-11T14:12:00Z")}

{"date":new ISODate("2014-12-11T14:12:00Z")}


and it always says "Error Parsing JSON".

Just wish to note that we have taken this conversation to the ticket system with Hamlet.

Thanks.

Since no one answered this question and I have a feeling that someone will encounter this problem again, I'll post a working solution. Use the extended JSON of mongodb to specify the date data type.


{ logtime : {"$date" : "2016-07-11T03:54:59Z"} }


2 people like this
Login to post a comment