[SERVER-59309] update with aggregation pipeline and array position not working as expected Created: 12/Aug/21 Updated: 17/Aug/21 Resolved: 17/Aug/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.4.8 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andreas Hald | Assignee: | Edwin Zhou |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
If you attempt to update an array on a document using the dot notation the result is not correct Given the document
and the operation
the result is as expected
But if I supply the same $set operation as part of an aggregation pipeline the result is very different
The result is as follows
|
| Comments |
| Comment by Edwin Zhou [ 17/Aug/21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi ah@21risk.com, I apologize for the delay and thank you for your patience while I investigate this issue. Thank you for correcting the repro script; I'm now able to see the issue you're running into. This appears to describe Best, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andreas Hald [ 17/Aug/21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi again Edwin, were you able to reproduce the issue with my update repro.js?
Best, Andreas | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andreas Hald [ 12/Aug/21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Edwin, thanks for getting back to me so quickly. As I tried to explain when providing an update query directly it works as expected, just as you do in the repro.js, however if you provide the same updateQuery as part of an aggregation pipeline, it works differently. I've modified repro.js here
As you can see the only change I've made is that the $set operation in the findOneAndUpdate is nested in an array. This appears to be valid in the docs (https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndUpdate/#use-an-aggregation-pipeline-for-updates) however the result is wrong. I apologise for not explaining it well enough the first time.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Edwin Zhou [ 12/Aug/21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi ah@21risk.com, Thanks for your report. I was unable to reproduce your behavior and based on the reproduction script below, I was able to receive your expected result:
result:
You can run the script with the following command (sans any authentication connection parameters):
Can you confirm that you're working on MongoDB v4.4.8, and can you work with the script I provided above to reproduce the issue you're seeing? Best, |