I'm using aggregate query. I need to return a document if:
- "total" doesn't exist
- array size is lower then "total"
So hide all document that have ALL array equal to "total".
Notes:
- "container" can have different "subContainer"
- "subContainer" is a dynamic key name
- "total" is optional
- "arr" size <= "total"
Documents in collection:
[
{ // "container.subContainer2.arr" is lower then "total"
"_id": 1,
"title": "title1",
"container": {
"subContainer1": {
"arr": [1, 2, 3]
},
"subContainer2": {
"arr": [1]
}
},
"total": 3
},
{ // "total" unknow
"_id": 2,
"title": "title2",
"container": {
"subContainer3": {
"arr": [1, 2, 3, 4]
}
}
},
{ // both array size are equal to "total"
"_id": 3,
"title": "title3",
"container": {
"subContainer4": {
"arr": [1, 2, 3, 4, 5]
},
"subContainer5": {
"arr": [1, 2, 3, 4, 5]
}
},
"total": 5
}
]
Output:
[
{
"title": "title1"
},
{
"title": "title2"
}
]
subContaineror all of thesubContainersizes?subContainerhas onearrarray. Should all of them be lower thattotalor at least one?subContainerhas at least onearrarray. All of them can be lower or equaltotal.