Here is a sample of the data I have:
{
"_id": ObjectId("52ed12c144aecc4bf004d0b6"),
"active": true,
"name": "woslo",
"specialDays": [
{
"_id": ObjectId("5f0576196198a715b0a72c14")
"status": true
"date": 2020-07-08T04:00:00.000+00:00
},
{
"_id": ObjectId("5f05a3726198a715b0a72c94")
"status": false
"date": 2020-07-09T04:00:00.000+00:00
}
]
}
I am trying to retrieve records using this query:
db.serviceProviders.aggregate([ { $match: { specialDays: { $elemMatch: { $or: [ { $and: [ { date: model.date // 2020-07-09T06:00:00.000Z }, { status: true } ] }, { date: { $ne: model.date //2020-07-09T06:00:00.000Z } } ] } } } } ]);
The scenario is as follows: if the date is present in the specialDays array and the status should be true, or the date should not be in the specialDays object's array, then fetch this record. However, it keeps returning the same record even when the status is false or the date is in the array. Can you please assist me in finding a solution? I have tried multiple MongoDB Compass aggregation queries with ISODate('2020-07-08') but without success. Thank you and happy coding.