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

Add option for mongoimport to upsert with $set instead of replacing the updated documents

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.4
    • Tools
    • None

    Description

      An upsert operation in MongoDB has different outcomes depending on the field values that are passed to it:

      If the <update> argument includes only field and value pairs, the new document contains the fields and values specified in the <update> argument. If the <update> argument includes only update operators, the new document contains the fields and values from <query> argument with the operations from the <update> argument applied.

      The current (and historical) behaviour of mongoimport with --upsert is to only pass through field & value pairs, which replaces any matching documents found: https://github.com/mongodb/mongo/blob/r2.4.4/src/mongo/tools/import.cpp#L463

      This has the side effect of removing any existing fields that aren't included in the import.

      It would be useful to add an option like --merge which would do the upsert using $set instead, in order to merge the field values from the mongoimport with the existing document fields.

      Attachments

        Activity

          People

            Unassigned Unassigned
            stephen.steneker@mongodb.com Stennie Steneker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: