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

$unwind with a path that traverses through arrays omits results

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL

      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@mongodb.com Alya Berciu
            Reporter:
            hana.pearlman@mongodb.com Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: