[SERVER-20499] Aggregation $project generates new array fields differently than new non-array fields Created: 18/Sep/15  Updated: 09/Jul/16  Resolved: 23/Sep/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.1.8
Fix Version/s: None

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

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

This aggregation, when aaaa and bbbb are both non-existent fields generates inconsistent result:

db.foo.aggregate({$project:{aaaa:"$aaaa", bbbb: [ "$bbbb" ]}})
{ "_id" : ObjectId("55cce7defd4e487ca8f05319"), "bbbb" : [ null ] }
{ "_id" : ObjectId("55cce7defd4e487ca8f0531a"), "bbbb" : [ null ] }
{ "_id" : ObjectId("55cce7defd4e487ca8f0531b"), "bbbb" : [ null ] }
{ "_id" : ObjectId("55cce7defd4e487ca8f0531c"), "bbbb" : [ null ] }

I would have expected aaaa to be missing and bbbb to be an empty array, not an array with explicit null. That seems more consistent with aaaa showing up with null value.



 Comments   
Comment by Charlie Swanson [ 23/Sep/15 ]

Closing as 'Works as Designed', as this was the intended behavior. The rationale was that by substituting null instead of removing it, the array indices stay the same. If you construct an array with 3 elements, it will always have 3 elements. This need to be documented more clearly, but I don't think the behavior should change.

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