How to Import a Mongo database from a cloud server to your local machine in 2 minutes

This short article helps you import/clone/copy a mongo database sitting on a cloud server i.e AWS, Digital Ocean, or other onto your local when you need data to test without having to create datasets manually.

Open your terminal application on your local machine
Ssh into your cloud server using this command:

This creates a tunnel to the remote mongo database server and tunnels it through port 27117 to the local machine

In the instance you find the port is already in use, you can append the port to 27019 or you can free it using the following commands:

Kill the process using the PID:

Now that we have mapped our remote server database to our local server port 27018. Next, we can copy from the remote server to our destination server using MongoDB’s mongodump/mongorestore pipeline using this command:

To understand the *mongodump* and *mongorestore* commands, read more on these links:

Now we check the database on our local:
Use this command to initiate the mongo shell:

Check all databases on the local machine:

We should be able to see our copied database on the list of on our local machine

Here is a screenshot of the whole operation for reference :
You should be able to see the **hashnode_example **database on the list



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

Software Developer (Javascript{NodeJS},Golang) and Mobile Apps(Flutter)