[SERVER-53896] positional $ operator when there are two array path in query Created: 20/Jan/21  Updated: 04/Mar/21  Resolved: 09/Feb/21

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

Type: Bug Priority: Major - P3
Reporter: Ali Rahbari Assignee: Charlie Swanson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-18500 Resolve ambiguity of positional proje... Backlog
Related
related to DOCS-14267 Clarify ambiguous $ positional operat... Closed
Operating System: ALL
Sprint: Query Optimization 2021-02-22
Participants:

 Description   

having following document:

{
  "user": [1],
  "grades": [
    {"grade": 80, "mean": 75, "std": 40},
    {"grade": 85, "mean": 90, "std": 45},
    {"grade": 90, "mean": 85, "std": 50}
  ]
}

 

this query:

db.students.updateOne(
  { user: 1, "grades.grade": 85 },
  { $set: { "grades.$.std" : 6 } }
)

 

update first element in grades instead of second one.



 Comments   
Comment by Charlie Swanson [ 09/Feb/21 ]

Hi rahbari@gmail.com,

Thanks for the report. This is indeed strange and unhelpful behavior. I think that this problem is already described and tracked in SERVER-18500. I'm resolving this ticket as a duplicate of that one, but please let me know if it doesn't look like the same thing to you. 

Comment by Edwin Zhou [ 22/Jan/21 ]

Hi rahbari@gmail.com,

Thanks for your bug report. The issue seems to happen when querying an array for an element then using $set and $pull with the positional operator. $pull with the positional operator works as intended when the document contains user: 1 instead of user: [1].

However, since the document is queried by both user and grades.grade, I would expect the positional operator to preserve the match made by the grades.grade field.

Best,
Edwin

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