[SERVER-58185] Expected update pipeline behavior of $merge Created: 30/Jun/21 Updated: 03/Sep/21 |
|
| Status: | Investigating |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Alice Thum | Assignee: | Katya Kamenieva |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Sprint: | QE 2021-08-23 |
| Participants: |
| Description |
|
I have some sample data as follows:
When running a pipeline with $merge:
This results in no error, and no updates to the "another" collection. Is this expected? I assumed this would not be allowed as there is a restriction on the "whenMatched" pipeline not updating the "on" field. Another example, using a different "on" field:
Pipeline:
It seems that in this case I run into a duplicate key error as we attempt to insert a results document. What is the correct behavior in this case? |
| Comments |
| Comment by Asya Kamsky [ 03/Sep/21 ] | ||||
|
Second example is invalid because you didn't specify `on:["item"]` if you do then it updates and unsets the `item` field. Without it it's merging on `_id` so it's doing an insert.
| ||||
| Comment by Asya Kamsky [ 03/Sep/21 ] | ||||
|
To rephrase:
should error just like a regular update does:
| ||||
| Comment by Asya Kamsky [ 30/Jun/21 ] | ||||
|
> This results in no error, and no updates to the "another" collection. Is this expected? Oplog examination shows that it does update another collection but it's a replacement with existing document i.e. no-op except for oplog entry... | ||||
| Comment by Asya Kamsky [ 30/Jun/21 ] | ||||
|
Note that this seems to be related to the fact that pipeline update which tries to change `_id` doesn't give an error:
Examining the oplog entry shows it did a replace of full document
|