Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43702

redact with nested arrays

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      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

       

       

            Assignee:
            carl.champain@mongodb.com Carl Champain (Inactive)
            Reporter:
            paulo.nuno.leite@gmail.com Paulo Leite
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: