...

/

Export and Import a MongoDB Database

Export and Import a MongoDB Database

Learn and practice utilities to export and import a MongoDB database or a MongoDB collection.

In this lesson, we’ll learn how to export and import a MongoDB database. MongoDB provides command-line tools mongodump and mongorestore to export and import a MongoDB database, respectively. These tools are installed by default with the MongoDB Database Tools package.

Export a MongoDB database

The mongodump command-line tool can export the following:

  • One database
  • All the databases
  • Specific collection of a database

Dump all the databases

The following command is used to dump all the databases.

mongodump

This creates a dump folder in the same directory you run the command in. The dump contains folders for each database.

If authorization is enabled, we provide a username with mongodump.

mongodump -u <username>

This will prompt us to enter a password. If the password is entered successfully, it dumps all the databases.

Dump specific database

Run the below command to dump ...