How to back-up and restore remote monogo db to local server

It may sound difficult at first but it is very easy to backup and restore a mongodb database. Here are the steps to achieve this –
- Download and install Mongodb CLI db tools from this link on both remote server as well as local machine –
https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools
While installing remember the path where this installer is placing its files. For windows the default mongo db tools path that it took was C:\Program Files\MongoDB\Tools\100\bin
- On server, open terminal and make the mongo db tools path as your present working directory and run this command –
mongodump
Since we are not passing any attributes to this command, it will create back up of all running databases under a dump folder which you can now see in present working directory.
Copy the database folder that you want to restore on local and transfer it to your local system.
- On your local machine, create a new folder called dump under mongo db tools path and paste the copied folder.
- On your local machine, open terminal and make the mongo db tools path as your present working directory and run this command
mongorestore
This will restore/create a database in your local mongodb server.
P.S
Before running these commands, make sure your mongo db server is running.