-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:
Description
The $ positional operator behaves ambiguously when there are multiple matching arrays. The work tracked on SERVER-18500 has not seen any progress, but we see this ambiguity causing issues with some users in SERVER-54687 and SERVER-53896.
https://docs.mongodb.com/manual/reference/operator/update/positional/
We should clarify we currently don't guarantee which array we get the position from when using the positional operator when there are multiple array matches.
Example:
doc = { a: [1, 2], z: [1, 2], b: [1, 2] } db.coll.insert(doc); db.coll.update({ a: 1, z: 2, b: 1 }, { $set: { "b.$": 3 } });
There is ambiguity around which index of the matched arrays (0 or 1) should we update b.
The current behavior returns:
{ "a" : [ 1, 2 ], "z" : [ 1, 2 ], "b" : [ 1, 3 ] }
where we update b using the index matched in z (index 1).
We may be able to guide users to consider $[<identifier>] if they need to make changes to an array based on a specified position. An example of favoring $[<identifier>] over $ can be found in my closing comment on SERVER-54687
Scope of changes
Impact to Other Docs
MVP (Work and Date)
Resources (Scope or Design Docs, Invision, etc.)
- is related to
-
SERVER-53896 positional $ operator when there are two array path in query
- Closed
-
SERVER-54687 `$pull`ed index should not override query-matched index for `$(update)`
- Closed