I try to query my events by their dates. So every event has a start date and a end date.
The structure of my Collection where these Events are inside is the following:
{
"_id": "5f2a7feae0c4e10017308fe5",
"events": [
{
"_id": "5f2a802ce0c4e10017308fe8",
"end": {
"dateTime": "2020-08-05T23:46:00.000Z"
},
"start": {
"dateTime": "2020-08-05T22:46:00.000Z"
}
}, ...
]
}
So I tried the following Aggregation Method:
The start and end values are ISO-Strings which are in my case the beginning and the end of an year.
Collection.aggregate([
{ $match: {owner: owner_id}},
{$unwind: '$events'},
{ $match :
{ 'events.start.dateTime':
{$gte: start,
$lt: end
}
}
},
{$sort: {'events.start.dateTime': 1}},
{$group: {_id: '$_id', 'events': {$push: '$events'}}}
])
When I try it with the $match filter I get an empty Array back. But if I try it without the $match filter. I get all events from the collection back.
Does someone know where the problem could be?