How can I save new Date() in MongoDB?

Raheel Aslam picture Raheel Aslam · Mar 17, 2017 · Viewed 13.2k times · Source

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

Answer

GPX picture GPX · Mar 17, 2017

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