[SERVER-6131] decide on behavior to $unwind an empty array Created: 19/Jun/12  Updated: 15/Aug/12  Resolved: 13/Jul/12

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

Type: Improvement Priority: Major - P3
Reporter: Aaron Staple Assignee: Aaron Staple
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The documentation says $unwind of an empty array passes through the source document unchanged. There are code comments stating that the behavior is to replace the empty array with a null value when unwinding. The actual behavior appears to be that the array field is removed from the document.

c = db.c;
c.drop();
 
c.save( { a:[] } );
printjson( c.aggregate( { $unwind:'$a' } ) );



 Comments   
Comment by auto [ 14/Jul/12 ]

Author:

{u'date': u'2012-07-13T16:54:37-07:00', u'email': u'aaron@10gen.com', u'name': u'astaple'}

Message: SERVER-6131 Describe new behavior when $unwind is applied to missing and empty array values.
Branch: master
https://github.com/mongodb/docs/commit/68ef50dbca93df330303e3f3445d119dc0066511

Comment by auto [ 13/Jul/12 ]

Author:

{u'date': u'2012-07-13T14:57:59-07:00', u'email': u'aaron@10gen.com', u'name': u'Aaron'}

Message: SERVER-6269 SERVER-6131 Reorganize DocumentSourceUnwind so that it iterates properly and omits documents lacking values to unwind.
Branch: master
https://github.com/mongodb/mongo/commit/0da867190d44c77ddf5ffd468c0c0028cd9e653f

Comment by Eliot Horowitz (Inactive) [ 27/Jun/12 ]

array with data - normal
array with no entries - nothing emitted, nothing in the result
null or undefined, nothing emitted, nothing in the the result
something besides a array, null, undefined - uassert

Comment by Aaron Staple [ 26/Jun/12 ]

@eliot - Does your comment above mean if the field is present but not an array (or if it is not present and has a non object parent) then the field should not be present in the result? Currently we just uassert in these cases.

Comment by auto [ 26/Jun/12 ]

Author:

{u'date': u'2012-06-26T12:29:04-07:00', u'email': u'aaron@10gen.com', u'name': u'astaple'}

Message: SERVER-6131 Correct description of behavior when $unwind is applied to an empty array. (The specified field is dropped from the result.)
Branch: master
https://github.com/mongodb/docs/commit/97effea2ffc0082a1af4ae13d254fdabe2ea5aed

Comment by Eliot Horowitz (Inactive) [ 23/Jun/12 ]

I actually both of those are wrong.
WIth no array field or an empty array, it should simply not be in the result.

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