In my bucket the documents have this structure
{
"version" : 1,
"root1" : "root1",
"root2" : "root2",
"i" : [
{
"i1" : "i1",
"i2" : "i2",
"p" : [
{
"id" : 1,
"p2" : "p2",
"tr" : [
{
"id" : 1,
"x" : "VALID",
"check" : false
},
{
"id" : 2,
"x" : "INVALID",
"check" : false
}
]
},
{
"id" : 2,
"p2" : "p2",
"tr" : [
{
"id" : 1,
"x" : "VALID",
"check" : true
},
{
"id" : 2,
"x" : "INVALID",
"check" : true
}
]
}
]
}
]
}
i is an array that contains the field p which is also an array and it contains also another array field tr
I want to return all document that have tr.x = "VALID" and check = false and eliminate from it trthat doesn't much this criteria.
So for the last example the return should be
{
"version" : 1,
"root1" : "root1",
"root2" : "root2",
"i" : [
{
"i1" : "i1",
"i2" : "i2",
"p" : [
{
"id" : 1,
"p2" : "p2",
"tr" : [
{
"id" : 1,
"x" : "VALID",
"check" : false
}
]
}
]
}
]
}
To select:
This simply nests the conditions for each nested array until the individual fields can be filtered.
An approach to returning only the matched array data is to apply similar logic:
which just replaces (the OBJECT_PUT functions) elements with filtered elements at each nesting level. The same element selection is repeated at each level since the filtering occurs on the elements before the OBJECT_PUT is applied.
Undoubtedly there are other approaches too.
HTH.