Details
-
Bug
-
Resolution: Won't Do
-
Major - P3
-
None
-
None
-
Query
-
ALL
-
Description
> db.test.insert({_id: 0, a: [1, 3, 5]})
|
> db.test.aggregate({$project: {"a.0": {$literal: 10}}})
|
{ "_id" : 0, "a" : [ { "0" : 10 }, { "0" : 10 }, { "0" : 10 } ] }
|
This behavior replaces every element of the array, when what $set does is more elegant:
> db.test.update({a: [1, 3, 5]}, {$set: {"a.0": 10}})
|
> db.test.find()
|
{ "_id" : 0, "a" : [ 10, 3, 5 ] }
|
However, $set errors when "a" is not an array.
This behavior occurs in both the $project stage and the new $addFields stage.
Attachments
Issue Links
- is related to
-
SERVER-5781 Implement $addFields aggregation stage for using expression language to add new fields to a document
-
- Closed
-
- related to
-
SERVER-30812 When using an array element as the local field for $lookup, $project doesn't work
-
- Closed
-