-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Critical - P2
-
None
-
Affects Version/s: 3.2.1
-
Component/s: Aggregation Framework
-
None
-
ALL
-
On 3.0, an expression like the following will work:
{ $project: { _id: 0, entities:{ $ifNull : [ '$entities', [ {'name' : 'No Entity'} ] ] } }
but on 3.2.1, it will generate the following error, since it tries to interpret the object literal {name: 'No Entity'} as an expression:
assert: command failed: { "ok" : 0, "errmsg" : "field inclusion is not allowed inside of $expressions", "code" : 16420 } : aggregate failed _getErrorWithCode@src/mongo/shell/utils.js:23:13 doassert@src/mongo/shell/assert.js:13:14 assert.commandWorked@src/mongo/shell/assert.js:266:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5 @(shell):1:1 2016-01-20T13:02:55.869-0400 E QUERY [thread1] Error: command failed: { "ok" : 0, "errmsg" : "field inclusion is not allowed inside of $expressions", "code" : 16420 } : aggregate failed : _getErrorWithCode@src/mongo/shell/utils.js:23:13 doassert@src/mongo/shell/assert.js:13:14 assert.commandWorked@src/mongo/shell/assert.js:266:5 DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1215:5 @(shell):1:1
The workaround is to wrap the object in a $literal expression, like so:
{ $project: { _id: 0, entities:{ $ifNull : [ '$entities', [ {$literal: {'name' : 'No Entity'} } ] ] } }