[DOCS-15957] [Server] Missing Example for $merge aggregation stage Created: 11/Mar/23  Updated: 30/Oct/23  Resolved: 19/Oct/23

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

Type: Task Priority: Minor - P4
Reporter: Dmitry Ryabtsev Assignee: Lauren Tran
Resolution: Won't Do Votes: 0
Labels: server-docs-bug-bash
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 15 weeks, 6 days ago

 Description   

The section for $merge stage is missing an example for whenMatched set for an update pipeline to merge subdocument fields if present

It would be nice to have at least a basic example added. Something along these lines:

replset:PRIMARY> db.b.find()
{ "_id" : ObjectId("640bc2b614d5a9fb72bca9b4"), "a" : { "b" : 1 } }
replset:PRIMARY> db.a.find()
{ "_id" : ObjectId("640bc2b614d5a9fb72bca9b4"), "a" : { "a" : 1 } }
replset:PRIMARY> db.b.aggregate([{"$merge": { "into": "a", "on": "_id", "whenMatched": [ { "$set": { "a.b": "$$new.a.b" } } ], "whenNotMatched": "discard"}}] )
replset:PRIMARY> db.a.find()
{ "_id" : ObjectId("640bc2b614d5a9fb72bca9b4"), "a" : { "a" : 1, "b" : 1 } }

https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/



 Comments   
Comment by Lauren Tran [ 19/Oct/23 ]

Closing this ticket after discussion with the OP - conclusion is that the desired documentation can be found through a combination of the existing examples combined with the more specific documentation on embedded/nested documents

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