My sample document is:
{
"_id": 1,
"offers": [
{
"id": 12345,
"amount": 100,
"eligibleProducts": [
111,
123,
156
]
},
{
"id": 12346,
"amount": 100,
"eligibleProducts": [
222,
333
]
}
]
}
I want to filter the offers with eligibleProducts.
If my eligibleProducts are [111, 777, 888] then return this:
{
"id": 12345,
"amount": 100,
"eligibleProducts": [
111,
123,
156
]
}
I used $setIsSubset aggregate but this is comparing with a full array,
"Offers" : { "$filter" : { "input" : "$Offers", "as" : "offer", "cond" : { "$and" : [{ "$setIsSubset" : {[111, 777, 888], "$$offer.eligibleProducts"]}}]}}}