Sure it is, just clearing up the syntax but you basically had it:
{
"opened": {
"$elemMatch": {
"closed": false,
"$or": [
{
"openingEvening": { "$lte": currentTime },
"closingEvening": { "$gte": currentTime }
},
{
"openingMorning": { "$lte": currentTime },
"closingMorning": { "$gte": currentTime }
}
]
}
}
}
And given a sample idea of the data:
{
"_id" : ObjectId("537969cee90c3db84958aa86"),
"opened" : [
{
"closed" : false,
"openingEvening" : 17,
"closingEvening" : 22,
"openingMorning" : 11,
"closingMorning" : 14
}
]
}
{
"_id" : ObjectId("53796a47e90c3db84958aa87"),
"opened" : [
{
"closed" : false,
"openingMorning" : 13,
"closingMorning" : 14
}
]
}
A current time of 12
would match the first but not the second document but a value of 13
would match both.
Also noting that these are within an array so given your estimated purpose you probably want a “dayOfWeek” field to include in there as well