Search⌘ K

Export and Import a MongoDB Database

Explore how to use the mongodump and mongorestore command-line tools to export and import MongoDB databases and collections. Learn to handle authentication, specify databases or collections, and manage external database connections for efficient data transfer.

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 ...