I have date string like
2022-05-17
And My mongodb collection document like
{
"_id": { "$oid": "aabbccddeeff" },
"title": "test",
"content": "test",
"author": "tester",
"churchId": { "$oid": "e5eakjshuwb3546" },
"markAsRead": false,
"createdAt": { "$date": "2022-05-17T08:18:57.174Z" },
"updatedAt": { "$date": "2022-05-17T08:18:57.174Z" },
"__v": 0
}
Now How do I find this collection using date string like mention above.
I have used this query as well
.find({ churchId, createdAt: new Date(createdAt) }, ' -__v')
But couldn’t work.
2
Answers
If project environment like typescript ,then
ISODate
shows an error like:So we can use
new Date()
class like:You can do something like
It will bring all the docs falls on the given day.