Importing / Exporting Data in MongoDB
Commands to deal with data in Mongo, mongodump, mongorestore
If you’re using MongoDB and need to copy, move, backup, import, export, or do something with your data, here are a few commands that should help.
From the terminal, (not inside the Mongo Shell)
Exporting
mongodump -d < database name > -o < output file >
If connecting from outside the database server, you might need to pass some additional parameters.
Parameter | Example |
---|---|
—host | mongodb.example.com |
—port | 23456 |
—username | user |
—password | yourpass |
Example Use:
mongodump --host mongodb.example.com --port 23456 --username user --password yourpass -o /database-dump-01-01-1970
Importing
mongorestore -d < database name > /path/to/database/files