How to fetch the data of particular date in mongoose? How to fetch the data of particular date in mongoose? mongoose mongoose

How to fetch the data of particular date in mongoose?


It seems that you have a syntax error:

const dat=new Date(2020,07,23);  const ndat=new Date(2020,07,24);  const sid=req.shop._id;  Order.find({shopId:sid,created_at: {"$gte": dat, "$lt": ndat}})  .then(data=>{    res.send(data);  })

OR this also works

  const sid=req.shop._id;  Order.find({shopId:sid,created_at: {"$gte": new Date(2020,07,23), "$lt": new Date(2020,07,24)}})  .then(data=>{    res.send(data);  })


MongoDB stores timestamps, not dates. Ensure the date you are passing is converted to timestamps that cover your order, and ensure that your order has the creation timestamp that you think it has.

Use mongo shell to find out what is actually stored in your database, and get the queries working in mongo shell first before trying to do them in your application.