[SERVER-39783] Updating Element in the Array using the positional $ operator Created: 23/Feb/19 Updated: 26/Feb/19 Resolved: 26/Feb/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | 3.6.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Venkatesh | Assignee: | Eric Sedor |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
Tried on MongoDB server version: 3.6.2 Steps to reproduce the problem.
Steps to show changing field name makes it work as expected. Note the only change is array element field name is changed from "s" to "a"
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Participants: |
| Description |
|
MongoDB Update is working inconsistently when using the positional $ operator to update an array element. It seems to be always updating the first element and not the element matching the query condition. Found that update is working as expected when the array element field name is changed from "s" to "a". Please see steps to reproduce for more details. Found the issue on MongoDB server version: 3.6.2. Not sure if it is present in all versions. |
| Comments |
| Comment by Eric Sedor [ 26/Feb/19 ] | |
|
Hi, thanks for writing in. $elemMatch should help you target specific array elements more accurately. For example, per this documentation the following should work:
For further questions about using specific MongoDB features, please post on the mongodb-user group or Stack Overflow with the mongodb tag. |