[SERVER-9943] Add option for mongoimport to upsert with $set instead of replacing the updated documents Created: 17/Jun/13  Updated: 17/Jun/13  Resolved: 17/Jun/13

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 2.4.4
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Stennie Steneker (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates TOOLS-69 MongoImport -- Support For Merge Imports Closed
Related
Participants:

 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.



 Comments   
Comment by Scott Hernandez (Inactive) [ 17/Jun/13 ]

Dup of SERVER-1674

Generated at Thu Feb 08 03:21:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.