14

When inserting a document into a MongoDB database with MongoDB Compass how do I insert the current date?

I have tried like so:

enter image description here

But as you can see there is an error.

How do I insert the current date using MongoDB Compass?

BugHunterUK
  • 8,346
  • 16
  • 65
  • 121

3 Answers3

16

Try like this:

{
"type":"grunt",
"last_used": {
        "$date": "2018-04-15T16:54:40.000Z"
    },
"created_at": {
        "$date": "2018-04-15T16:54:40.000Z"
    }
}
David Buck
  • 3,752
  • 35
  • 31
  • 35
13

Try like this:

2016-01-24T13:21:55.000
Alireza
  • 6,497
  • 13
  • 59
  • 132
tatsuya
  • 162
  • 2
  • 4
1

Try like this

{
"type": "grunt",
"last_used": {"$date":{"$numberLong":"1602720972129"}},
"created_at":{"$date":{"$numberLong":"1602720972129"}}
}

Joe
  • 86
  • 3