Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I save new Date() in MongoDB?

Tags:

mongodb

robo3t

When I save a date time in MongoDB using the following format, it shows:

Error "Unable to parse JSON" 

{
  "_id" : ObjectId("58cb759805aeeae37a56dd3d"),
  "name" : "Plutus",
  "admin" : "type 1",
  "created" : new Date()
}

Please help me to save a date time in Robomongo using MongoDB in the above format.

Error description in picture:

Error message

Thanks

like image 678
Raheel Aslam Avatar asked Mar 17 '17 05:03

Raheel Aslam


1 Answers

You could try using new ISODate("2017-03-17 11:59"). I know it is a little cumbersome, but this is the only date value that is guaranteed to work across all versions of Robomongo and MongoDB.

Further reading -

  1. https://github.com/Studio3T/robomongo/issues/614
  2. https://github.com/Studio3T/robomongo/issues/477
like image 56
GPX Avatar answered Oct 06 '22 12:10

GPX