
- 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
Find posts that are older than current date in MongoDB?
To find posts older than current date in MongoDB, use $lte. Let us create a collection with documents −
> db.demo746.insertOne({DueDate:new Date("2020-01-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eca930c785c834e55b") } > db.demo746.insertOne({DueDate:new Date("2020-10-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eda930c785c834e55c") } > db.demo746.insertOne({DueDate:new Date("2020-03-05")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eea930c785c834e55d") } > db.demo746.insertOne({DueDate:new Date("2020-05-04")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67f1a930c785c834e55e") }
Display all documents from a collection with the help of find() method −
> db.demo746.find();
This will produce the following output −
{ "_id" : ObjectId("5eae67eca930c785c834e55b"), "DueDate" : ISODate("2020-01-10T00:00:00Z") } { "_id" : ObjectId("5eae67eda930c785c834e55c"), "DueDate" : ISODate("2020-10-10T00:00:00Z") } { "_id" : ObjectId("5eae67eea930c785c834e55d"), "DueDate" : ISODate("2020-03-05T00:00:00Z") } { "_id" : ObjectId("5eae67f1a930c785c834e55e"), "DueDate" : ISODate("2020-05-04T00:00:00Z") }
Following is the query to find posts older than the current date −
> db.demo746.find({DueDate:{$lte:new Date()}});
This will produce the following output −
"_id" : ObjectId("5eae67eca930c785c834e55b"), "DueDate" : ISODate("2020-01-10T00:00:00Z") } { "_id" : ObjectId("5eae67eea930c785c834e55d"), "DueDate" : ISODate("2020-03-05T00:00:00Z") }
- Related Questions & Answers
- Selecting rows that are older than current date in MySQL?
- MySQL query to delete a DATE older than 30 days from another date?
- How to select a date less than the current date with MySQL?
- Compare date when the AdmissionDate is less than the current date in MySQL
- Deleting all rows older than 5 days in MySQL
- Find current and previous documents in MongoDB
- MySQL query to select rows older than a week?
- How to delete rows older than 14 days in MySQL?
- Delete records where timestamp older than 5 minutes in MySQL?
- How to select rows in MySQL that are >= 1 DAY from the current date?
- MySQL select * and find record with current date
- MySQL query to delete all rows older than 30 days?
- Fetching rows updated at timestamp older than 1 day in MySQL?
- Find data for specific date in MongoDB?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
Advertisements