Few Commands about Import/Export Mongo Database
Table of Contents
Introduction
With MongoDB's mongodump and mongorestore commands, you can export
and import data to your Mongo database.
Export Database
Go to your local Mongo bin folder. Type mongodump --db {your database name}.
This command will export all your database data as binary files under the dump folder. When I had 200 MB with a total collection of around 50,000 documents, this command ran in about 2–3 seconds on my Windows 8 (8GB memory) PC.
Restore Your Database to a Remote Connected Database
Assume your remote Mongo database has nothing and you just want to import everything you just exported from the local Mongo database. Run the following command:
mongorestore --db {your database} --host {server name} --port {server port number} --username {your database user name} --password {your database user's password} dump/{your database name}
Conclusion
MongoDB's mongodump and mongorestore commands provide a simple and fast way to export and import data between local and remote databases. These two commands are essential tools for database backup and migration.