Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Finding data between two dates by using a query in mongoose

How would I write a query which checks the createdAt and finds all objects between 2022-05-22 and 2022-06-22? I tried the following code/ API, but it didn’t give back the right data :

getPoDetails = async (req, res, next) => {
    try {
        let fromDate = req.query.fromDate;
        let toDate = req.query.toDate;
        var findQry = {};
        if(fromDate && toDate) {
            findQry.createdAt = {$gte: new Date(fromDate), $lte: new Date(toDate)};
        }
        allmodels.poDetailsModel.find(findQry)
        .then(data => res.status(200).send(data))
        .catch(err => res.status(400).send(err));
    } catch (error) {
        next(error);
    }
}

API link : localhost:8000/getPoDetails?fromDate=2022-05-22&toDate=2022-06-22

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!