Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Compass - How To Insert Date Type?

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?

like image 436
BugHunterUK Avatar asked Apr 15 '18 15:04

BugHunterUK


3 Answers

Try like this:

{
"type":"grunt",
"last_used": {
        "$date": "2018-04-15T16:54:40.000Z"
    },
"created_at": {
        "$date": "2018-04-15T16:54:40.000Z"
    }
}
like image 157
FrancisMarconcini Avatar answered Nov 10 '22 06:11

FrancisMarconcini


Try like this:

2016-01-24T13:21:55.000
like image 37
tatsuya Avatar answered Nov 10 '22 08:11

tatsuya


Try like this

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

like image 1
Joe Avatar answered Nov 10 '22 08:11

Joe