If you are developing rails application with mongodb, sometime you may want to synchronise your production database, or remote database to local for development or testing purpose. The following command will help you do that:

mkdir tmp-dump && cd tmp-dump && mongodump --host [YOUR_DB_SERVER] -u [DATABASE_USER] -p [DATABASE_PASSWORD] -d [DATABASE_NEED_TO_RESTORE] rake db:drop && rake db:create && mongorestore && cd .. && rm -rf tmp-dump

Firstly, open terminal and change current directory to your rails app folder. Next, replace content in square brackets (and the brackets as well) with your corresponding information. Press ENTER and wait for the job done 🙂

Credit: Li Soon – techlist developer


(adsbygoogle = window.adsbygoogle || []).push({});