-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.1.8
-
Component/s: Aggregation Framework
-
None
-
Minor Change
-
ALL
-
QuInt A (10/12/15)
SERVER-4588 has the following behavior:
> db.foo.find() { "_id" : 0, "a" : [1], "b" : "foo" } { "_id" : 1, "a" : 1, "b" : "bar" } > db.foo.aggregate({$unwind:{ path: "$a", includeArrayIndex: true}}) { "_id" : 0, "a" : { "index" : NumberLong(0), "value" : 1 }, "b" : "foo" } { "_id" : 1, "a" : 1, "b" : "bar" }
If I now want to do something with "a" value, I have to use an extra project with $ifNull "a.value" in order to find the value of "a" which is in "a".
We should allow the user to specify which field the array index should go into. This will override any existing fields, and if the value was not produced from an element in an array (i.e. there is no sensical index to use), we should use the value null instead:
> db.foo.aggregate({$unwind:{ path: "$a", includeArrayIndex: "$b"}}) { "_id" : 0, "a" : 1, "b" : NumberLong(0) } { "_id" : 1, "a" : 1, "b" : null }
- depends on
-
DRIVERS-234 Aggregation Builder Support for 3.2
- Closed
- is depended on by
-
CSHARP-1433 Add option to $unwind to emit array index
- Closed
-
JAVA-1995 Add option to $unwind to emit array index
- Closed
- related to
-
SERVER-4588 aggregation: add option to $unwind to emit array index
- Closed