Cloning / restoring / migrating MongoDB with mongodump

There is an easy way to migrate MongoDB database between different hosts. Sometimes we might need it for example in case of:

  • moving db from local database to the remote

And any other possible case you might think about.

With mongodump it’s only 2 simple steps.

First you will need to install mongodump for your platform:

Then first step is to create the dump:

mongodump --uri='URLOFMONGO'

'URLOFMONGO' is URL you are using to connect your app to MongoDB -- either local like let's say mongodb:// or remote like mongodb+srv://

It will save the dump — the whole content of your database — in the dumpfolder in the current folder from there the command was executed.

Inside dump folder you would see the folder with the name of the DB - it's the one you would like to use to restore.

To restore:


such as

mongorestore --uri='mongodb://' -d winemind dump/Winemind

Now we moved data from remote DB called Winemind to localhost DB named winemind

The end :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Barcelona Code School

We help people to learn web development and improve their lives by becoming a freelancer, finding a job or starting their own product. Just coding, no bullshit!