

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I save new Date() in MongoDB?
To save new Date() in MongoDB, you can use new ISODate(). Let us create a collection with documents −
> db.saveDateDemo.insertOne({"UserName":"John","UserLoginDatetime":new ISODate('2018-01-31 12:34:56')}); { "acknowledged" : true, "insertedId" : ObjectId("5cbd67d4de8cc557214c0e04") } > db.saveDateDemo.insertOne({"UserName":"John","UserLoginDatetime":new ISODate('2019-02-01 04:01:10')}); { "acknowledged" : true, "insertedId" : ObjectId("5cbd67e8de8cc557214c0e05") } > db.saveDateDemo.insertOne({"UserName":"John","UserLoginDatetime":new ISODate('2019-04-22 12:36:45')}); { "acknowledged" : true, "insertedId" : ObjectId("5cbd6805de8cc557214c0e06") }
Display all documents from a collection with the help of find() method −
> db.saveDateDemo.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5cbd67d4de8cc557214c0e04"), "UserName" : "John", "UserLoginDatetime" : ISODate("2018-01-31T12:34:56Z") } { "_id" : ObjectId("5cbd67e8de8cc557214c0e05"), "UserName" : "John", "UserLoginDatetime" : ISODate("2019-02-01T04:01:10Z") } { "_id" : ObjectId("5cbd6805de8cc557214c0e06"), "UserName" : "John", "UserLoginDatetime" : ISODate("2019-04-22T12:36:45Z") }
- Related Questions & Answers
- How can I save HTML locally with JavaScript?
- How can I save a HashMap to Shared Preferences in Android?
- How can I save a HashMap to Sharedpreferences in Android Kotlin?
- How to use save() correctly in MongoDB?
- How can I rename a collection in MongoDB?
- How can I update child objects in MongoDB?
- How can I aggregate nested documents in MongoDB?
- How can I earn from learning a new language?
- How can I update child objects in MongoDB database?
- How can I change the field name in MongoDB?
- MongoDB - how can I access fields in a document?
- How can I subtract a day from a Python date?
- How can I get time and date since epoch in JavaScript?
- How can I get the current time and date in Kotlin?
- Set variable value in MongoDB save() method
Advertisements