-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
ALL
want to prune the elements of a nested array which do not satisfy a certain condition:
The structure of my document is:
{"array1":[{"array2":[{"field1":{"field2":"MATCH"}}]}]}The redact query I´m trying to do is: db.getCollection("collection").aggregate([{"$match" : {"array1.array2.field1.field2" : "MATCH",{"$redact" : {"$cond" : {"if" :
{"$in" : ["$array1.array2.field1.field2",["MATCH"]]},"then" : "$$KEEP","else" : "$$PRUNE"}}}]);}}
I never can get any result. However if I replace "$array1.array2.field1.field2" with "MATCH" I get a true condition and keeps all the documents. My question is what am I doing wrong for the value of the expression "$array1.array2.field1.field2" never to be equal to "MATCH" if it is the value of field2?
I also need the returned documents in its original structure.
I'm using MongoDB 4.0