Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-40429

Add $merge stage to write output to existing collection

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.11
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Fully Compatible
    • Query 2019-04-22, Query 2019-05-06

      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.

            Assignee:
            anton.korshunov@mongodb.com Anton Korshunov
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: