Mongodb – Merge 2 mongodb databases

mongodb

Our team have hard time. Situation:

  1. API went down, all infrastructure (API + MongoDB) terminated.
  2. We restore API and mongodb (data restored from backup).
  3. After a while (let's say 1 day) we discovered we used not latest backup, but backup from month ago. We cannot just shutdown API and restore from latest backup, because users already created data for 1 day.

State: on our prod DB 1 month of production data has been lost. But in the same time we have this gap inside backup.

Question: what is best solution to merge missing data to existing prod? Better with no downtime.

P.S. Because if this we had to create some data manually, for example, recreate some users. What gonna happen when we merge these 2 DBs?

Best Answer

Bring second instance up, restore data to that instance. Then mongoexport data to json files what you can mongoimport to current mongodb with "--mode upsert --upsertFields '_id'" (using _id as a key)