There have been questions with similar titles, but none of them seem to suit my needs.
{
'_id': '4e51b88f-b62f-4b62-81208e6011c9a388',
'name': 'dinky', 'phone': '91216098',
'blacklist': False,
'events': [
{
'startsAt': '2018-07-16T18:00:53.397',
'endsAt': '2018-07-16T18:10:53.397',
'title': 'dinky Appointment',
'note': ''
},
{
'startsAt': '2018-07-30T18:00:00.000',
'endsAt': '2018-07-30T18:10:00.000',
'title': 'dinky',
'note': ''
},
{
'startsAt': '2018-08-02T18:08:54.247',
'endsAt': '2018-08-02T18:18:54.247',
'title': 'dinky',
'note': ''
},
{
'startsAt': '2018-08-09T18:45:09.146',
'endsAt': '2018-08-09T18:55:09.146',
'title': 'dinky',
'note': ''
}
],
'additionalPhones': []
}
The above is a sample document. I want to query base on event.startsAt date. The result I want are events that match that date.
This is what I have tried.
todaysEvent = db.find({"events": { "$elemMatch": {"startsAt": { "$regex": "2018-08-09" }}}} )
However, when I used this, I end up getting documents that have events from this day, but it shows all other events that are not part of that date. I only want to show events that match that date.
FYI, I am using pymongo.
Thank you!