- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Find records on or after a specific date in MongoDB?
To find records on or after a date, use $gte i.e., greater than equal. Let us create a collection with documents −
> db.demo91.insertOne({"ArrivalDate":new ISODate("2020-01-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5e2d49fd79799acab037af66") } > db.demo91.insertOne({"ArrivalDate":new ISODate("2019-12-14")}); { "acknowledged" : true, "insertedId" : ObjectId("5e2d4a0679799acab037af67") }
Display all documents from a collection with the help of find() method −
> db.demo91.find();
This will produce the following output −
{ "_id" : ObjectId("5e2d49fd79799acab037af66"), "ArrivalDate" : ISODate("2020-01-10T00:00:00Z") } { "_id" : ObjectId("5e2d4a0679799acab037af67"), "ArrivalDate" : ISODate("2019-12-14T00:00:00Z") }
Following is the query to find records on or after a specific date in MongoDB −
> db.demo91.find({ArrivalDate: { $gte: ISODate('2020-01-10') } });
This will produce the following output −
{ "_id" : ObjectId("5e2d49fd79799acab037af66"), "ArrivalDate" : ISODate("2020-01-10T00:00:00Z") }
Advertisements