We have a shop collection as below.
We need to return all UNIQUE 'shop'
having NO batch as empty([]
).
Since this is a stage in the aggregation - it would not be able to avail of index.
So we need to find the most efficient way to do the above.
{
"_id": ObjectId("xxxxxx"),
"shop": "Q4",
"batch": ["5647"],
},
{
"_id": ObjectId("xxxxxx"),
"shop": "Q4",
"batch": ["2314", "0121"],
},
{
"_id": ObjectId("xxxxxx"),
"shop": "Q1",
"batch": ["5647"],
},
{
"_id": ObjectId("xxxxxx"),
"shop": "Q1",
"batch": [],
}
Expected result : Q4
Try this :
Collection Data :
Result :