
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
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 Articles
- How can I save HTML locally with JavaScript?
- How to use save() correctly in MongoDB?
- How can I save a HashMap to Shared Preferences in Android?
- How can I save a HashMap to Sharedpreferences in Android Kotlin?
- How can I rename a collection in MongoDB?
- How can I update child objects in MongoDB?
- How can I convert string date to NSDate?
- How can I aggregate nested documents in MongoDB?\n
- 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?
- I want to create a new field in an already created document. How can this be done using MongoDB query?
- How to insert Date in MongoDB?
- How can we save water?
- How can I earn from learning a new language?

Advertisements