MongoDB: Import/Export a Database with Command Line
If you’re using MongoDB, you can export or import a whole database by using a single command line. All of the collections of that database will be exported/imported at once. It’s super convenient when backup/restore data.
Exporting a database
Run the following command from your system command line:
mongodump -d [your database name] -o [output directory]
If you want to export a remote database with a password, run:
mongodump --host [host address] --port 27017 --db [your database name] --username [your user name] --password [your password] --out [output directory]
You can find more information about the mongodump utility in the documentation.
Importing a whole database
In order to import or restore a database, execute the following command:
mongorestore -d [your database name] [backup directory]
The larger your database, the longer it will take. You can find more details about mongorestore here.