Thursday, April 22, 2021

MongoDB upsert vs drop

Based on the mongo doc, the reason --mode=upsert doesn't work in your case is by default, mongoimport uses the _id field. So --drop should be the correct answer.


--mode=upsert:


By default, mongoimport uses the _id field to match documents in the collection with documents in the import file. To specify the fields against which to match existing documents for the upsert and merge modes, use --upsertFields.


--drop:


Modifies the import process so that the target instance drops the collection before importing the data from the input.


references:

https://stackoverflow.com/questions/29775398/mongoimport-json-file-update-or-overwritte

No comments:

Post a Comment