[DOCS-12818] Highlight that _id should be removed before using $merge without _id in 'on' fields Created: 21/Jun/19  Updated: 30/Oct/23  Resolved: 05/Jul/19

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Charlie Swanson Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 4 years, 31 weeks, 5 days ago
Epic Link: DOCS: 4.2 Server/Tools

 Description   

Description

When designing the $merge stage we realized that using a set of 'on' fields other than _id will often result in the user accidentally trying to modify the _id of the target document. When the 'whenMatched' mode is "merge" (the default), the update generated by the $merge stage will include the _id from the document in the pipeline which is likely different than the one targeted by the 'on' fields. Further, because $project includes the _id by default, it might not be obvious to users whether the document going into $merge has an _id at all.

cc asya

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 05/Jul/19 ]

Author:

{'name': 'Kay Kim', 'username': 'kay-kim', 'email': 'kay.kim@10gen.com'}

Message: DOCS-12818: merge and _id field
Branch: master
https://github.com/mongodb/docs/commit/698ce7cd4534073df873436ac0be158bf937e68a

Comment by Kay Kim (Inactive) [ 21/Jun/19 ]

We currently state

When performing a merge, the merged document cannot result in a modification of the _id value or, if the output collection is sharded, the shard key value.

Will add the aforementioned workaround of removing the _id field.

as well as include the workaround in https://docs.mongodb.com/master/reference/operator/aggregation/merge/#existing-documents-and-id-and-shard-key-values section

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