How To Install, Back Up and Restore MongoDB

1. Installation MongoDB 

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update 
sudo apt-get install mongodb-org

 

2. Dump MongoDB

Go to folder contain db_backup

mongodump --host <hostname> --port <portnumber> --db <database_name> -u <username> -p<password> -o .
mongodump -h app_demo.mongolab.com:3000 -d app_demo123 -u user_app123 -p pwd123 -o .

 

3. Restore MongoDB

mongorestore -h localhost -d app_demo --drop . (all file in folder)

or:

mongorestore -h localhost -d app_demo --drop [db_dump_folder]