Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in SQL by (47.6k points)

I've seen using strings, integer timestamps and mongo datetime objects.

1 Answer

0 votes
by (106k points)

The best way to store date/time in MongoDB which is also native JavaScript Date objects, which map onto BSON native Date objects.

> db.test.insert({date: ISODate()}) 

> db.test.insert({date: new Date()}) 

> db.test.find() 

{ "_id" : ObjectId("..."), "date" : ISODate("2014-02-10T10:50:42.389Z") } 

{ "_id" : ObjectId("..."), "date" : ISODate("2014-02-10T10:50:57.240Z") } 

Related questions

0 votes
1 answer
asked Jul 4, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Jul 23, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer

Browse Categories

...