[SERVER-20595] Unwind with includeArrayIndex produces different structure results for arrays and non-arrays Created: 23/Sep/15  Updated: 28/Oct/15  Resolved: 07/Oct/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.1.8
Fix Version/s: 3.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Charlie Swanson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on DRIVERS-234 Aggregation Builder Support for 3.2 Closed
is depended on by CSHARP-1433 Add option to $unwind to emit array i... Closed
is depended on by JAVA-1995 Add option to $unwind to emit array i... Closed
Related
related to SERVER-4588 aggregation: add option to $unwind to... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: QuInt A (10/12/15)
Participants:

 Description   

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 }



 Comments   
Comment by Githook User [ 13/Oct/15 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-20595 The includeArrayIndex option to $unwind should specify a path
Branch: artree
https://github.com/10gen/mongo-enterprise-modules/commit/f19868188089c72bea1d088904f3637446d7d7d6

Comment by Githook User [ 07/Oct/15 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-20595 The includeArrayIndex option to $unwind should specify a path
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/f19868188089c72bea1d088904f3637446d7d7d6

Comment by Githook User [ 07/Oct/15 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-20595 The includeArrayIndex option to $unwind should specify a path
Branch: master
https://github.com/mongodb/mongo/commit/9c46f951450271310fa818a6dbb30411f088007d

Comment by Charlie Swanson [ 01/Oct/15 ]

After some discussion, we have decided that allowing the user to specify a path to put the index into is a little better than always putting the index into a sub-document. The description has been updated accordingly.

Generated at Thu Feb 08 03:54:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.