I have a mongo collection which stores information about products & it has an embedded array that stores its availability datewise.
{
"product_id": "A",
"name": "mountain bicycle",
"cost_per_hour": "$5",
"availability":[
{
"timestamp": ISODate("2018-11-19 18:30:00.000Z"),
"available": true
},
{
"timestamp": ISODate("2018-12-20 18:30:00.000Z")
"available": true
},
{
"timestamp": ISODate("2018-12-21 18:30:00.000Z")
"available": false
}
]
}
I want to list all the products that are available on all dates in a given date interval.
Example: If I query for date between ISODate("2018-11-19 18:30:00.000Z") To ISODate("2018-12-20 18:30:00.000Z") AND available: true, I should get a product with "product_id": "A", since its available on all dates between the date interval.
But If I query between ISODate("2018-11-19 18:30:00.000Z") To ISODate("2018-12-21 18:30:00.000Z") AND available: true, I should NOT get any results since the product is NOT available on all dates in the date range.
I tried using $elemMatch but that returns products that are available in at least 1 of the dates given in the interval, which I don't want.
Please guide.