0

I need to get all records from MongoDB collection "employee" where joining_date is between current_date and current_date + 5 days. I couldn't find anything similar to BETWEEN operator in MongoDB documentation. Below query works fine in Google BigQuery. Looking for similar solution in MongoDB.

select * from employee where joining_date BETWEEN current_date() and DATE_ADD(current_date(), interval 5 DAY);
Towkir
  • 3,889
  • 2
  • 22
  • 41
  • Possible duplicate of [Find objects between two dates MongoDB](https://stackoverflow.com/questions/2943222/find-objects-between-two-dates-mongodb) – Valijon Oct 12 '19 at 14:23

1 Answers1

1

The $gt and $lt Comparison Query Operators can be used to find matches within a range of dates. Here's one approach.

db.employee.find({
    "joining_date": {
        $gt: new Date(),
        $lt: new Date(new Date().setDate(new Date().getDate() + 5))
    }
})
It'sNotMe
  • 1,184
  • 1
  • 9
  • 29