When you use mongoimport to import files into MongoDB, you have the option of replacing existing documents that match the ones you’re importing.
By this I mean, if an imported document has the same _id value as an existing one in the collection you’re importing into, the existing document will be replaced with the one being imported.
You can also specify another field (other than the _id field) to be the matching field if required.
The way to replace existing documents when using mongoimport is to use upsert mode.