This is my dataset from MongoDB Collection:
{
"_id": "60c0ace96e93993880efd337",
"lv": [
uid: 1,
"createdate": "2021-12-15T12:30:01.935Z",
"updatedAt": [
"2021-12-15T12:31:11.635Z",
"2021-12-15T12:31:51.955Z",
"2021-12-16T12:30:01.935Z",
"2021-12-16T12:30:01.935Z",
"2021-12-17T12:30:01.935Z",
"2021-12-18T12:30:01.935Z"
]
]
},
{
...
}
I want to filterout only the data which date range lies in createdate column or updatedAt column.
I am not able to get the desired result. Not getting the idea that where I am making the mistake in the query or coed.
What I have tried I will mention here.
let startA = new Date("2021-12-14");
const a = new Date(startA.setHours(startA.getHours() - 5));
const start = new Date(a.setMinutes(startA.getMinutes() - 30));
let endA = new Date("2021-12-17");
const b = new Date(endA.setHours(endA.getHours() - 5));
const end = new Date(b.setMinutes(endA.getMinutes() - 30));
const fetchData = await MyCollection.findOne(
{
_id: ObjectId(req.body.id),
'lv.createdate': { $gte: start, $lt: end },
'lv.updatedAt': {
$elemMatch: { $gte: start, $lt: end }
}
}
).lean().exec();
Any help or suggestion is really appreciated. Thanks in advance for the interaction.