Importing / Exporting Data in MongoDB

11-10-2019

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

1
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:

1
mongodump --host mongodb.example.com --port 23456 --username user --password yourpass -o /database-dump-01-01-1970

Importing

1
mongorestore -d < database name > /path/to/database/files