Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save henrik/a1006443e454bc7bb8134f8d0e471d30 to your computer and use it in GitHub Desktop.
Save henrik/a1006443e454bc7bb8134f8d0e471d30 to your computer and use it in GitHub Desktop.
How to restore a downloaded MongoDB.com backup dump

We had a downloaded MongoDB dump that we wanted to restore on cloud.MongoDB.com. This is how we did it:

  1. Download the backup via the MongoDB web UI.

  2. Unzip it. In this example we assume it unzipped to /tmp/foo.

  3. Have MongoDB installed locally, e.g. via:

     brew tap mongodb/brew
     brew install mongodb-community
    
  4. Start a local Mongo server:

    mongod --dbpath /tmp/foo
    
  5. Dump the local Mongo server (will create a dump directory in the current working directory):

    mongodump
    
  6. Restore the remote DB from this dump:

    mongorestore --uri mongodb+srv://myuser:[email protected]/ --drop dump
    

    Note that --drop only drops the same collections as you're importing! Any collections that aren't in your local dump will remain in the remote DB unless you wipe it first.

    We just removed the collections one by one via their web UI, but please comment with better solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment