Frage

I have a mongo-database where existing entries never change but new entries are added every day. I have ~1000 dumps, each is the new data that was added on the corresponding day.

I.e. I have the following files:

/dump1/mydatabase/mycollection1.bson
/dump1/mydatabase/mycollection1.metadata.json
/dump1/mydatabase/mycollection2.bson
/dump1/mydatabase/mycollection2.metadata.json
...
/dump2/mydatabase/mycollection1.bson
/dump2/mydatabase/mycollection1.metadata.json
/dump2/mydatabase/mycollection2.bson
/dump2/mydatabase/mycollection2.metadata.json
...
...
...
/dump1000/mydatabase/mycollection1.bson
/dump1000/mydatabase/mycollection1.metadata.json
/dump1000/mydatabase/mycollection2.bson
/dump1000/mydatabase/mycollection2.metadata.json

I would like to restore "mydatabase" containing all the collections. The content in each of the collections should be appended to the existing collections instead of overwriting them.

When I run

mongorestore /dump1
mongorestore /dump2
...

will this append my data to the existing collections or overwrite them?

War es hilfreich?

Lösung

Find below the wordings from MongoDB official documentation

Insert Only

mongorestore can create a new database or add data to an existing database. However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.

To answer your question, no the documents won't be overwritten.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit dba.stackexchange
scroll top