[SERVER-58521] Dot notation updates with arrays can lead to nonsensical results Created: 14/Jul/21  Updated: 06/Dec/22  Resolved: 22/Jul/21

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

Type: Bug Priority: Major - P3
Reporter: Ross Lawley Assignee: Backlog - Query Optimization
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-24748 Aggregation does not provide a way to... Backlog
Related
related to SERVER-27442 Positional path component in match la... Backlog
related to SERVER-24748 Aggregation does not provide a way to... Backlog
Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

Enterprise test> db.dropDatabase()
Enterprise test> db.test.insert({_id: 1, arr_a: [1, 3]});
Enterprise test> db.test.insert({_id: 2, arr_a: [1, 3]});
Enterprise test> db.test.updateOne({_id: 1}, {$set: {"arr_a.0": 2}});    
Enterprise test> db.test.updateOne({_id: 2}, [{$set: {"arr_a.0": 2}}]);
Enterprise test> db.test.find()
[
  { _id: 1, arr_a: [ 2, 3 ] },
  { _id: 2, arr_a: [ { '0': 2 }, { '0': 2 } ] }
]

Participants:

 Description   

The documentation isn't clear that dot notation behaviour with arrays using $set provides very different results than using $set with arrays.

The behaviour is surprising.



 Comments   
Comment by Asya Kamsky [ 22/Jul/21 ]

It's definitely strongly related to SERVER-24748 and while docs could be improved, without a simple way to specify index in agg update syntax, it's going to be a complex docs section.

Comment by David Storch [ 16/Jul/21 ]

Unfortunately, I believe this is working as designed. Improving the documentation would be a good idea. Providing a language facility in pipeline-based updates to permit positional array updates, or generally improving array updates in the pipeline update language is something we considered in the past but ultimately deprioritized.

I am going to reassign this to the Query Optimization team's triage queue, since this is more related to MQL semantics.

Generated at Thu Feb 08 05:44:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.