MongoDB Compass - How To Insert Date Type?
Asked Answered
U

3

16

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?

Underwater answered 15/4, 2018 at 15:49 Comment(0)
K
14

Try like this:

2016-01-24T13:21:55.000
Kreit answered 31/7, 2018 at 9:11 Comment(0)
C
22

Try like this:

{
"type":"grunt",
"last_used": {
        "$date": "2018-04-15T16:54:40.000Z"
    },
"created_at": {
        "$date": "2018-04-15T16:54:40.000Z"
    }
}
Confluence answered 1/10, 2020 at 3:28 Comment(0)
K
14

Try like this:

2016-01-24T13:21:55.000
Kreit answered 31/7, 2018 at 9:11 Comment(0)
J
1

Try like this

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

Johan answered 15/10, 2020 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.