I am very new to MongoDB and have just started learning and working with it. I have a question about a query. This is the query:
db.getCollection("user_plates").count(
{
"plates": {
$elemMatch: {
registerDate: {
$gt: new Date("2024-03-20T00:00:00.000Z"),
$lt: new Date("2024-03-21T00:00:00.000Z")
}
}
}
}
);
As you know, if the query find at least one element in the array that satisfies both condition, it returns all the elements of that document. Now, I need to have only the elements from the array of that document, that the field "registerDate" satisfies both conditions. I do not want to see other elements of the array of that document. How should I modify the above query to achieve this?
Thanks in advance