Currently, I am attempting to filter data based on a specific id (bWYqm6-Oo) and dates between 2019-09-19 and 2019-09-22. The desired result should return the first three items from the database. However, my current query is returning an empty array. I would appreciate any assistance in resolving this issue. Thank you!
var findBy = {
_id : bWYqm6-Oo,
exercises : [
{
date: {
$gte: 2019-09-19,
$lt: 2019-09-22
}
}
]
}
UserModel.find(findBy).limit(5).exec((err, data) => {
(err) ? res.json({"error" : "problem searching for exercises: " + err}) : res.json(data);
});
The structure of my database:
{
_id: "bWYqm6-Oo",
user: "rommy",
exersises: [
{
user_id: "bWYqm6-Oo",
date: "2019-09-20T00:00:00.000Z",
description: "stiup",
duration: "22",
_id: "pu90D-dHx"
},
{
user_id: "bWYqm6-Oo",
date: "2019-09-21T00:00:00.000Z",
description: "pushup",
duration: "22",
_id: "YtfsJLOXb"
},
{
user_id: "bWYqm6-Oo",
date: "2019-09-20T00:00:00.000Z",
description: "stiup",
duration: "22",
_id: "pu90D-dHx"
},
{
user_id: "bWYqm6-Oo",
date: "2019-09-24T00:00:00.000Z",
description: "stiup",
duration: "22",
_id: "pu90D-dHx"
}
],
__v: 9
}
In my server.js file, here is where I call my files: