[SERVER-40429] Add $merge stage to write output to existing collection Created: 01/Apr/19  Updated: 29/Oct/23  Resolved: 02/May/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 4.1.11

Type: New Feature Priority: Major - P3
Reporter: Charlie Swanson Assignee: Anton Korshunov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-40430 Add $merge support for whenMatched: '... Closed
is depended on by SERVER-40431 Add $merge support for whenMatched: p... Closed
is depended on by SERVER-40438 Add $merge support for whenNotMatched... Closed
is depended on by SERVER-40439 Add $merge support for whenNotMatched... Closed
is depended on by SERVER-40440 Add $merge support for whenMatched: '... Closed
is depended on by SERVER-41175 Ensure $merge is not allowed in $look... Closed
Documented
is documented by DOCS-12675 Docs for SERVER-40429: Add $merge sta... Closed
Related
is related to SERVER-2517 Allow mapReduce to create full documents Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2019-04-22, Query 2019-05-06
Participants:

 Description   

This stage replaces the new modes of $out.

The syntax is:

{$merge: {
  into: "collection name" OR {db: "db name", coll: "collection name"},
  on: <fields used to uniquely identify a document>,
  let: <optional, variables to be in scope for pipeline below>,
  whenMatched: "replace|keepExisting|fail|merge|pipeline",
  whenNotMatched: "insert|discard|fail"
}}

This ticket tracks support for the combination of modes already supported by $out:
mode "insertDocuments":

{$merge: {
  into: "x",
  on: "x_id"
  whenMatched: "fail",
  whenNotMatched: "insert"
}}

mode "replaceDocuments":

{$merge: {
  into: "x",
  on: "x_id"
  whenMatched: "replaceWithNew",
  whenNotMatched: "insert"
}}

Support for other modes is tracked in their own tickets.



 Comments   
Comment by Githook User [ 02/May/19 ]

Author:

{'email': 'anton.korshunov@mongodb.com', 'name': 'Anton Korshunov', 'username': 'antkorsh'}

Message: SERVER-40429 Add merge stage to write output to existing collection
Branch: master
https://github.com/mongodb/mongo/commit/fc6c65c0d4ffff4104e355af6f6c3d73b79ad713

Generated at Thu Feb 08 04:54:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.