Hello All,
I need some help in writing a query where in one of our collections we have a field which is an array(products) and it holds an array of objects . In each of this object we have a field called quantity1 and quanity2 where I need to fetch all the documents which has all the objects within that array has quantity1 and quantity2 as null.
Basically I need some thing exact opposite of what $nin can achieve.
Note: $in doesnt work because it will return even if there is one or more objects that doesn not match filter. The units within these quanitites can be anything as this is something coming from scraped data.
Example: For the below data the query should return only the 2nd document as its the only document which as all objects with quantity1 and quantity2 as null.
{
"_id": ObjectId("636a6aa584d5f92f14f0c548"),
"products": [
{
"quantity1": '10 grams',
"quantity2": '24 grams',
"user_id": "602cf72a3fcad3cc605b8d59"
},
{
"quantity1": '10 grams',
"quantity2": null,
"user_id": "602cf72a3fcad3cc605b8d50"
}
]
},
// 2
{"_id": ObjectId("602e443bacdd4184511d6e29"),
"products": [
{
"quantity1": 'null',
"quantity2": 'null',
"user_id": "602cf72a3fcad3cc605b8d59"
},
{
"quantity1": 'null',
"quantity2": 'null',
"user_id": "602cf72a3fcad3cc605b8d59"
},
{
"quantity1": 'null',
"quantity2": 'null',
"user_id": "602cf72a3fcad3cc605b8d59"
}
]
},
// 3
{"_id": ObjectId("60332242acdd4184511ed664"),
"products": [
{
"quantity1": 'null',
"quantity2": 'null',
"user_id": "602cf72a3fcad3cc605b8d59"
},
{
"quantity1": null,
"quantity2": 'null',
"user_id": "602cf72a3fcad3cc605b8d59"
},
{
"user_id": "602cf72a3fcad3cc605b8d59"
}
]
}
]```