$unwind with a path that traverses through arrays omits results

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The $unwind docs say: "When the operand does not resolve to an array, but is not missing, null, or an empty array, $unwind treats the operand as a single element array.". This should be a no-op. For example,

      MongoDB Enterprise > db.foo.insert({a: {b: 1}})
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise > db.foo.aggregate({$unwind: "$a.b"})
      { "_id" : ObjectId("67361c61681dab8a44bc64f9"), "a" : { "b" : 1 } }

      But when the $unwind path is a nested path that traverses through arrays, those documents are omitted from the output:

      MongoDB Enterprise > db.foo.drop()
      true
      MongoDB Enterprise > db.foo.insert({a: [{b: 1}, {b: 2}]})
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise > db.foo.insert({a: [{b: [1, 2]}]})
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise > db.foo.aggregate({$unwind: "$a.b"})
      MongoDB Enterprise >

              Assignee:
              Alya Berciu
              Reporter:
              Hana Pearlman
              Votes:
              0 Vote for this issue
              Watchers:
              13 Start watching this issue

                Created:
                Updated:
                Resolved: