Few Commands about How to Export/Import MongoDB Collections

6/1/2014·1 min read

Following example is export/import to your localhost's mongo database.

Export Collection from Mongo Database


Mongodb/bin>mongoexport --db {your database} --collection {your collection} --out {your file name}.json

Import Collection to Mongo Database


Mongodb/bin>mongoimport --db {your database} --collection {your collection} --file {your file name}.json

Import Collection to Mongo Database(remote)

Note: collection needs to be before --db.
Mongodb/bin>mongoimport --host {host server name} --port {server port number} --username {db username} --password {password} --collection {collection name} --db {database name} --file {your file name}.json

For detail information, reference following mongo document.