-
Type: Bug
-
Resolution: Unresolved
-
Priority: 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 >
- related to
-
SERVER-59713 `$unwind` doesn't work on array subdocument fields
- Investigating