-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.4.8
-
Component/s: None
-
ALL
If you attempt to update an array on a document using the dot notation the result is not correct
Given the document
{ _id: ObjectId('1234'), myArray: [ { someValue: false }, { someValue: true } ] }
and the operation
collection.findOneAndUpdate(new ObjectId('1234'), { $set: { 'myArray.0.someValue': true, 'myArray.1.someValue': true, } })
the result is as expected
{ _id: ObjectId('1234'), myArray: [ { someValue: true }, { someValue: true } ] }
But if I supply the same $set operation as part of an aggregation pipeline the result is very different
collection.findOneAndUpdate(new ObjectId('1234'), [ $set: { 'myArray.0.someValue': true, 'myArray.1.someValue': true, } ]})
The result is as follows
{ _id: ObjectId('1234'), myArray: [ { someValue: false, 0: { someValue: true}, 1: { someValue: true}, }, { someValue: true 0: { someValue: true}, 1: { someValue: true}, } ] }
- duplicates
-
SERVER-24748 Aggregation does not provide a way to access a specific element of an array
- Backlog