MongoDB Import / Export

If you want to export a whole database on MongoDB, this is the tool you are looking for:

mongodump --host <HOST> --port <PORT> --db <DATABASE> --username <USERNAME> --password <PASSWORD>

that will export all your collections into a separate folder. Each collection is exported to a single bson file. After you executed the command you will have a “dump” folder. Under the dump folder there is folder the the name of the DATABASE and under the database folder are the collections on separate bson files.

If you want to import the files into another MongoDB on another server, this is the tool you are looking for:

mongorestore --host <HOST> --port <PORT> --username <USERNAME> --port <PORT> dump/<DATABASENAME>

That worked for me fine šŸ™‚

 

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

One thought on “MongoDB Import / Export

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: