I have the following document:
{
"_ID": "234",
"sub": {
"abcId": "123",
"subElems": [
{
"abcId": "345",
"subElems": [
{
"abcId": "676",
"subElems": [
{
"abcId": "567"
},
{
"abcId": "567b",
"crit1": false,
"crit2": "someId",
"crit3": "2013-07-30T22:00:00.000+0000",
"crit4": "ABC"
},
{
"abcId": "567c",
"crit1": true,
"crit3": "2013-07-30T22:00:00.000+0000",
"crit4": "ABC"
},
{
"abcId": "567d",
"crit1": true,
"crit3": "2018-11-30T22:00:00.000+0000",
"crit4": "ABC"
}
]
},
{
"abcId": "678",
"subElems": [
{
"abcId": "568"
},
{
"abcId": "568b",
"crit1": false,
"crit2": "someId",
"crit3": "2013-07-30T22:00:00.000+0000",
"crit4": "ABC"
},
{
"abcId": "568c",
"crit1": true,
"crit3": "2013-07-30T22:00:00.000+0000",
"crit4": "ABC"
},
{
"abcId": "568d",
"crit1": true,
"crit3": "2018-11-30T22:00:00.000+0000",
"crit4": "ABC"
}
]
}
]
}
]
}
}
I need to iterate over all sub.subElems.0.subElems (in this case the nested documents with abcId 676 and 678)
Each of those 2 again have an array of objects called subElems.
I need to find all ojects in this subElems array that match the following criteria (AND, not OR):
crit1 = true
crit4 = ABC
crit2 = null
crit3 = more than a year ago
Given the collectin above, I need:
567c and 568c
I have a tried various aggregations.
I thought I could do something like unwind sub.subElems.0.subElems and then access its subElems array and iterate over that.
What I don't know how to do is select a nested aray of objects (whose path I know) but then iterate over the elements in this array and again iterate over an array in those objects.
Thanks for help and tips!