Hello
I have the following User schema:
const User = mongoose.model(
"User",
new mongoose.Schema({
email: String,
password: String,
name: String,
days: [
{
day: Date,
data:
{
average_score: {type: mongoose.Schema.Types.Decimal128, default: 0 }
}
}
]
})
);
In the day field I’m storing the days in ISO format like 2020-12-29T00:00:00.000Z. The User.find query is returning all the days instead of returning the data for the days between the Date range and I’m not sure why is this happening.
User.find({ "_id": getUserId(req), "days.day":{
"$gte": new Date("2021-01-02T00:00:00.000Z"),
"$lt": new Date("2021-01-04T00:00:00.000Z")
}},
function (err, result) {
if (err){
res.status(400).send({data: { message: err }});
return;
}
else if(result)
{
res.status(200).send({data: { message: result }});
}
})