The mongorestore tool imports content from binary database dump, created by mongodump into a specific database. mongorestore can import content to an existing database or create a new one.

mongorestore only performs inserts into the existing database, and does not perform updates or upserts. If existing data with the same _id already exists on the target database, mongorestore will not replace it.

mongorestore will recreate indexes from the dump

The behavior of mongorestore has the following properties:

  • all operations are inserts, not updates.

  • all inserts are "fire and forget," mongorestore does not wait for a response from a mongod to ensure that the MongoDB process has received or recorded the operation.

    The mongod will record any errors to its log that occur during a restore operation but mongorestore will not receive errors.


The format of data created by mongodump tool from the 2.2 distribution or later is different and incompatible with earlier versions of mongod.




Returns a basic help and usage text.

--verbose, -v

Increases the amount of internal reporting returned on the command line. Increase the verbosity with the -v form by including the option multiple times, (e.g. -vvvvv.)


Returns the version of the mongorestore tool.

--host <hostname><:port>

Specifies a resolvable hostname for the mongod to which you want to restore the database. By default mongorestore will attempt to connect to a MongoDB process running on the localhost port number 27017.

Optionally, specify a port number to connect a MongoDB instance running on a port other than 27017.

To connect to a replica set, you can specify the replica set seed name, and a seed list of set members, in the following format:


--port <port>

Specifies the port number, if the MongoDB instance is not running on the standard port. (i.e. 27017) You may also specify a port number using the --host command.


Enables IPv6 support that allows mongorestore to connect to the MongoDB instance using an IPv6 network. All MongoDB programs and processes, including mongorestore, disable IPv6 support by default.


New in version 2.4: MongoDB added support for SSL connections to mongod instances in mongorestore.


SSL support in mongorestore is not compiled into the default distribution of MongoDB. See /administration/ssl for more information on SSL and MongoDB.

Additionally, mongorestore does not support connections to mongod instances that require client certificate validation.

Allows mongorestore to connect to mongod instance over an SSL connection.

--username <username>, -u <username>

Specifies a username to authenticate to the MongoDB instance, if your database requires authentication. Use in conjunction with the --password option to supply a password.

--password <password>, -p <password>

Specifies a password to authenticate to the MongoDB instance. Use in conjunction with the mongorestore --username option to supply a username.

If you specify a --username without the --password option, mongorestore will prompt for a password interactively.

--authenticationDatabase <dbname>

New in version 2.4.

Specifies the database that holds the user's (e.g --username) credentials.

By default, mongorestore assumes that the database specified to the --db argument holds the user's credentials, unless you specify --authenticationDatabase.

See userSource, /reference/privilege-documents and /reference/user-privileges for more information about delegated authentication in MongoDB.

--authenticationMechanism <name>

New in version 2.4.

Specifies the authentication mechanism. By default, the authentication mechanism is MONGODB-CR, which is the MongoDB challenge/response authentication mechanism. In the MongoDB Subscriber Edition, mongorestore also includes support for GSSAPI to handle Kerberos authentication.

See /tutorial/control-access-to-mongodb-with-kerberos-authentication for more information about Kerberos authentication.

--dbpath <path>

Specifies the directory of the MongoDB data files. If used, the --dbpath option enables mongorestore to attach directly to local data files and insert the data without the mongod. To run with --dbpath, mongorestore needs to lock access to the data directory: as a result, no mongod can access the same path while the process runs.


Use the --directoryperdb in conjunction with the corresponding option to mongod, which allows mongorestore to import data into MongoDB instances that have every database's files saved in discrete directories on the disk. This option is only relevant when specifying the --dbpath option.


Allows mongorestore write to the durability journal to ensure that the data files will remain in a consistent state during the write process. This option is only relevant when specifying the --dbpath option.

--db <db>, -d <db>

Use the --db option to specify a database for mongorestore to restore data into. If the database doesn't exist, mongorestore will create the specified database. If you do not specify a <db>, mongorestore creates new databases that correspond to the databases where data originated and data may be overwritten. Use this option to restore data into a MongoDB instance that already has data.

--db does not control which BSON files mongorestore restores. You must use the mongorestore path option to limit that restored data.

--collection <collection>, -c <collection>

Use the --collection option to specify a collection for mongorestore to restore. If you do not specify a <collection>, mongorestore imports all collections created. Existing data may be overwritten. Use this option to restore data into a MongoDB instance that already has data, or to restore only some data in the specified imported data set.


Forces the mongorestore to validate all requests from clients upon receipt to ensure that clients never insert invalid documents into the database. For objects with a high degree of sub-document nesting, --objcheck can have a small impact on performance. You can set --noobjcheck to disable object checking at run-time.

Changed in version 2.4: MongoDB enables --objcheck by default, to prevent any client from inserting malformed or invalid BSON into a MongoDB database.


New in version 2.4.

Disables the default document validation that MongoDB performs on all incoming BSON documents.

--filter '<JSON>'

Limits the documents that mongorestore imports to only those documents that match the JSON document specified as '<JSON>'. Be sure to include the document in single quotes to avoid interaction with your system's shell environment.


Modifies the restoration procedure to drop every collection from the target database before restoring the collection from the dumped backup.


Replays the oplog after restoring the dump to ensure that the current state of the database reflects the point-in-time backup captured with the "mongodump --oplog" command.


Prevents mongorestore from upgrading the index to the latest version during the restoration process.

--w <number of replicas per write>

New in version 2.2.

Specifies the write concern for each write operation that mongorestore writes to the target database. By default, mongorestore does not wait for a response for write acknowledgment.


New in version 2.2.

Prevents mongorestore from setting the collection options, such as those specified by the collMod database command, on restored collections.


New in version 2.2.

Prevents mongorestore from restoring and building indexes as specified in the corresponding mongodump output.

--oplogLimit <timestamp>

New in version 2.2.

Prevents mongorestore from applying oplog entries newer than the <timestamp>. Specify <timestamp> values in the form of <time_t>:<ordinal>, where <time_t> is the seconds since the UNIX epoch, and <ordinal> represents a counter of operations in the oplog that occurred in the specified second.

You must use --oplogLimit in conjunction with the --oplogReplay option.


The final argument of the mongorestore command is a directory path. This argument specifies the location of the database dump from which to restore.


See /tutorial/backup-databases-with-binary-database-dumps for a larger overview of mongorestore usage. Also see the "mongodump" document for an overview of the mongodump, which provides the related inverse functionality.

Consider the following example:

mongorestore --collection people --db accounts dump/accounts/

Here, mongorestore reads the database dump in the dump/ sub-directory of the current directory, and restores only the documents in the collection named people from the database named accounts. mongorestore restores data to the instance running on the localhost interface on port 27017.

In the next example, mongorestore restores a backup of the database instance located in dump to a database instance stored in the /srv/mongodb on the local machine. This requires that there are no active mongod instances attached to /srv/mongodb data directory.

mongorestore --dbpath /srv/mongodb

In the final example, mongorestore restores a database dump located at /opt/backup/mongodump-2011-10-24, from a database running on port 37017 on the host mongorestore authenticates to the this MongoDB instance using the username user and the password pass, as follows:

mongorestore --host --port 37017 --username user --password pass /opt/backup/mongodump-2011-10-24


MongoDB Documentation Project


2011-2013, 10gen, Inc.