- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 to insert Date in MongoDB?
To insert date in MongoDB, use Date(). Let us create a collection with documents −
> db.demo421.insert({"DueDate":new Date(Date.now())}); WriteResult({ "nInserted" : 1 }) > db.demo421.insert({"DueDate":new Date("2020-01-15")}); WriteResult({ "nInserted" : 1 }) > db.demo421.insert({"DueDate":new Date("2018-12-31")}); WriteResult({ "nInserted" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo421.find();
This will produce the following output −
{ "_id" : ObjectId("5e73a2ec9822da45b30346de"), "DueDate" : ISODate("2020-03-19T16:50:52.746Z") } { "_id" : ObjectId("5e73a2fb9822da45b30346df"), "DueDate" : ISODate("2020-01-15T00:00:00Z") } { "_id" : ObjectId("5e73a3079822da45b30346e0"), "DueDate" : ISODate("2018-12-31T00:00:00Z") }
- Related Articles
- How to insert a document with date in MongoDB?
- How to insert date in single quotes with MySQL date formats?
- How to insert LONG numbers in MongoDB?
- How to insert current date/time in MySQL?
- How to insert a boolean field in MongoDB?
- How to insert a Python object in Mongodb?
- How to insert Date value into table in JDBC?
- How to insert date object in MySQL using Python?
- How to insert DATE in MySQL table with TRIGGERS?
- How to convert date to timestamp in MongoDB
- Convert date parts to date in MongoDB
- How to Insert custom date into MySQL timestamp field?
- How to validate documents before insert or update in MongoDB?
- How to convert US date format to MySQL format in INSERT query?
- How to match date with MongoDB $match?

Advertisements