Navigation
This version of the documentation is archived and no longer supported.

mongodump

macOS Sierra and Go 1.6 Incompatibility

Users running on macOS Sierra require the 3.2.10 or newer version of mongodump.

Upcoming Tools Migration in MongoDB 4.4

Starting in MongoDB 4.4, the mongodump documentation migrates to MongoDB Database Tools - mongodump. Refer to that page for more information on the upcoming version of mongodump (tool version 100.0.0).

The documentation on this page only applies to the MongoDB 4.2 version of mongodump. The MongoDB 4.2 version of mongodump is available for download following the instructions in the Availability section below.

Synopsis

mongodump is a utility for creating a binary export of the contents of a database. mongodump can export data from either mongod or mongos instances; i.e. can export data from standalone, replica set, and sharded cluster deployments.

Note

If you are archiving stale data to save on storage costs, consider Online Archive in MongoDB Atlas. Online Archive automatically archives infrequently accessed data to fully-managed S3 buckets for cost-effective data tiering.

Availability

The mongodump tool is part of the MongoDB tools package. Consult the installation guide for your platform for instructions on how to install the tools package as part of your MongoDB installation.

The tools package is also available from the MongoDB Download Center, either as a separate tools download, or contained within the TGZ or ZIP downloads, depending on platform. On Windows, the MSI installer includes all tools as part of the default installation.

Tip

If downloading the TGZ or ZIP files from the Download Center, you may want to update your PATH environment variable to include the directory where you installed these tools. See the installation guide for your platform for more information.

Usage in Backup Strategy

Standalones/Replica Sets

For standalone or a replica set, mongodump can be a part of a backup strategy with mongorestore for partial backups based on a query, syncing from production to staging or development environments, or changing the storage engine of a standalone.

For an overview of mongodump in conjunction with mongorestore part of a backup and recovery strategy, see:

Sharded Clusters

mongodump and mongorestore cannot be part of a backup strategy for 4.2+ sharded clusters that have sharded transactions in progress, as backups created with mongodump do not maintain the atomicity guarantees of transactions across shards.

For 4.2+ sharded clusters with in-progress sharded transactions, use one of the following coordinated backup and restore processes which do maintain the atomicity guarantees of transactions across shards:

Syntax

Run mongodump from the system command line, not the mongo shell.

mongodump [options]

Connect to a MongoDB Instance

To connect to a local MongoDB instance running on port 27017 and use the default settings to export the content, run mongodump without any command-line options:

mongodump

To specify a host and/or port of the MongoDB instance, you can either:

  • Specify the hostname and port in the --uri connection string:

    mongodump --uri="mongodb://mongodb0.example.com:27017" [additional options]
    
  • Specify the hostname and port in the --host:

    mongodump --host="mongodb0.example.com:27017"  [additional options]
    
  • Specify the hostname and port in the --host and --port:

    mongodump --host="mongodb0.example.com" --port=27017 [additional options]
    

For more information on the options available, see Options.

Connect to a Replica Set

To connect to a replica set to export its data, you can either:

  • Specify the replica set name and members in the --uri connection string:

    mongodump --uri="mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myReplicaSetName" [additional options]
    
  • Specify the replica set name and members in the --host:

    mongodump --host="myReplicaSetName/mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com" [additional options]
    

By default, mongodump reads from the primary of the replica set. To override the default, you can specify the read preference:

  • You can specify the read preference in the --uri connection string

    mongodump --uri="mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myReplicaSetName&readPreference=secondary" [additional options]
    

    If specifying the read preference tags, include the readPreferenceTags option:

    mongodump --uri="mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myReplicaSetName&readPreference=secondary&readPreferenceTags=region:east" [additional options]
    
  • You can specify the read preference in using the --readPreference command-line option. The command-line option takes a string if specifying only the read preference mode:

    mongodump --host="myReplicaSetName/mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017" --readPreference=secondary [additional options]
    

    Or, the command-line option can takes a quote-enclosed document '{ mode: <mode>, tagSets: [ <tag1>, ... ], maxStalenessSeconds:<num>}' to specify the mode, the optional read preference tag sets, and the optional maxStalenessSeconds:

    mongodump --host="myReplicaSetName/mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017" --readPreference='{mode: "secondary", tagSets: [ { "region": "east" } ]}' [additional options]
    

For more information on the options available, see Options.

Connect to a Sharded Cluster

To connect to a sharded cluster to export its data, you can either:

  • Specify the hostname of the mongos instance in the --uri connection string

    mongodump --uri="mongodb://mongos0.example.com:27017" [additional options]
    
  • Specify the hostname and port of the mongos instance in the --host

    mongodump --host="mongos0.example.com:27017" [additional options]
    

By default, mongodump reads from the primary of the shard replica set. To override the default, you can specify the read preference:

  • You can specify the read preference in the --uri connection string

    mongodump --uri="mongodb://mongos0.example.com:27017/?readPreference=secondary" [additional options]
    

    If specifying the read preference tags, include the readPreferenceTags option:

    mongodump --uri="mongodb://mongos0.example.com:27017/?readPreference=secondary&readPreferenceTags=region:east" [additional options]
    
  • You can specify the read preference in using the --readPreference command-line option. The command-line option takes a string if specifying only the read preference mode:

    mongodump --host="mongos0.example.com:27017" --readPreference=secondary [additional options]
    

    Or, the command-line option can takes a quote-enclosed document '{ mode: <mode>, tagSets: [ <tag1>, ... ], maxStalenessSeconds: <num>}' to specify the mode, the optional read preference tag sets, and the optional maxStalenessSeconds:

    mongodump --host="mongos0.example.com:27017" --readPreference='{mode: "secondary", tagSets: [ { "region": "east" } ]}' [additional options]
    

For more information on the options available, see Options.

See also

Examples

Behavior

Read Preference

By default, mongodump uses read preference primary. To override the default, you can specify the read preference in the --readPreference command-line option or in the --uri connection string.

Starting in version 4.2, if you specify read preference in the URI string and the --readPreference option, the --readPreference value overrides the read preference specified in the URI string.

In earlier versions, the two options are incompatible.

Data Exclusion

mongodump excludes the content of the local database in its output.

mongodump output only captures the documents in the database and does not include index data. mongorestore or mongod must then rebuild the indexes after restoring data.

Changed in version 3.4: MongoDB 3.4 added support for read-only views. By default, mongodump only captures a view’s metadata: it does not create a binary export of the documents included in the view. To capture the documents in a view use --viewsAsCollections.

Metadata Format

Starting in version 4.2, mongodump uses Extended JSON v2.0 (Canonical) format for the metadata files. To parse these files for restore, use mongorestore version 4.2+ that supports Extended JSON v2.0 (Canonical or Relaxed mode) format.

Tip

If general, use corresponding versions of mongodump and mongorestore. That is, to restore data files created with a specific version of mongodump, use the corresponding version of mongorestore.

Overwrite Files

mongodump overwrites output files if they exist in the backup data folder. Before running the mongodump command multiple times, either ensure that you no longer need the files in the output folder (the default is the dump/ folder) or rename the folders or files.

Data Compression Handling

When run against a mongod instance that uses the WiredTiger storage engine, mongodump outputs uncompressed data.

Working Set

mongodump can adversely affect performance of the mongod. If your data is larger than system memory, the mongodump will push the working set out of memory.

FIPS

Starting in version 4.2, MongoDB removes the --sslFIPSMode option for mongodump. mongodump will use FIPS compliant connections to mongod/mongos if the mongod/mongos instances are configured to use FIPS mode.

Required Access

To run mongodump against a MongoDB deployment that has access control enabled, you must have privileges that grant find action for each database to back up. The built-in backup role provides the required privileges to perform backup of any and all databases.

The backup role provides additional privileges to back up the system.profile collection that exists when running with database profiling.

Options

mongodump
--help

Returns information on the options and use of mongodump.

--verbose, -v

Increases the amount of internal reporting returned on standard output or in log files. Increase the verbosity with the -v form by including the option multiple times, (e.g. -vvvvv.)

--quiet

Runs mongodump in a quiet mode that attempts to limit the amount of output.

This option suppresses:

  • output from database commands
  • replication activity
  • connection accepted events
  • connection closed events
--version

Returns the mongodump release number.

--uri=<connectionString>

New in version 3.4.6.

Specify a resolvable URI connection string (enclose in quotes) to connect to the MongoDB deployment.

--uri="mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"

For information on the components of the connection string, see the Connection String URI Format documentation.

Note

For TLS/SSL options, use the command-line options instead of the URI options for TLS/SSL (Available starting in 4.2).

Important

The following command-line options cannot be used in conjunction with --uri option:

Instead, specify these options as part of your --uri connection string.

--host=<hostname><:port>, -h=<hostname><:port>

Default: localhost:27017

Specifies a resolvable hostname for the mongod to which to connect. By default, the mongodump attempts to connect to a MongoDB instance running on the localhost on port number 27017.

To connect to a replica set, specify the replSetName and a seed list of set members, as in the following:

--host=<replSetName>/<hostname1><:port>,<hostname2><:port>,<...>

When specifying the replica set list format, mongodump always connects to the primary.

You can also connect to any single member of the replica set by specifying the host and port of only that member:

--host=<hostname1><:port>

If you use IPv6 and use the <address>:<port> format, you must enclose the portion of an address and port combination in brackets (e.g. [<address>]).

Note

You cannot specify both --host and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

--port=<port>

Default: 27017

Specifies the TCP port on which the MongoDB instance listens for client connections.

Note

You cannot specify both --port and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

--ipv6

Removed in version 3.0.

Enables IPv6 support and allows mongodump to connect to the MongoDB instance using an IPv6 network. Prior to MongoDB 3.0, you had to specify --ipv6 to use IPv6. In MongoDB 3.0 and later, IPv6 is always enabled.

--ssl

Enables connection to a mongod or mongos that has TLS/SSL support enabled.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslCAFile=<filename>

Specifies the .pem file that contains the root certificate chain from the Certificate Authority. Specify the file name of the .pem file using relative or absolute paths.

If --tlsCAFile/net.tls.CAFile (or their aliases --sslCAFile/net.ssl.CAFile) is not specified and you are not using x.509 authentication, the system-wide CA certificate store will be used when connecting to an TLS/SSL-enabled server.

To use x.509 authentication, --tlsCAFile or net.tls.CAFile must be specified unless using --tlsCertificateSelector or --net.tls.certificateSelector. Or if using the ssl aliases, --sslCAFile or net.ssl.CAFile must be specified unless using --sslCertificateSelector or net.ssl.certificateSelector.

Warning

Version 3.2 and earlier: For TLS/SSL connections (--ssl) to mongod and mongos, if the mongodump runs without the --sslCAFile, mongodump will not attempt to validate the server certificates. This creates a vulnerability to expired mongod and mongos certificates as well as to foreign processes posing as valid mongod or mongos instances. Ensure that you always specify the CA file to validate the server certificates in cases where intrusion is a possibility.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslPEMKeyFile=<filename>

Specifies the .pem file that contains both the TLS/SSL certificate and key. Specify the file name of the .pem file using relative or absolute paths.

This option is required when using the --ssl option to connect to a mongod or mongos that has CAFile enabled without allowConnectionsWithoutCertificates.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslPEMKeyPassword=<value>

Specifies the password to de-crypt the certificate-key file (i.e. --sslPEMKeyFile). Use the --sslPEMKeyPassword option only if the certificate-key file is encrypted. In all cases, the mongodump will redact the password from all logging and reporting output.

If the private key in the PEM file is encrypted and you do not specify the --sslPEMKeyPassword option, the mongodump will prompt for a passphrase. See TLS/SSL Certificate Passphrase.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslCRLFile=<filename>

Specifies the .pem file that contains the Certificate Revocation List. Specify the file name of the .pem file using relative or absolute paths.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslAllowInvalidCertificates

Bypasses the validation checks for server certificates and allows the use of invalid certificates. When using the allowInvalidCertificates setting, MongoDB logs as a warning the use of the invalid certificate.

Starting in MongoDB 4.0, if you specify --sslAllowInvalidCertificates or net.ssl.allowInvalidCertificates: true (or in MongoDB 4.2, the alias --tlsAllowInvalidateCertificates or net.tls.allowInvalidCertificates: true) when using x.509 authentication, an invalid certificate is only sufficient to establish a TLS/SSL connection but is insufficient for authentication.

Warning

Although available, avoid using the --sslAllowInvalidCertificates option if possible. If the use of --sslAllowInvalidCertificates is necessary, only use the option on systems where intrusion is not possible.

If the mongo shell (and other MongoDB Tools) runs with the --sslAllowInvalidCertificates option, the mongo shell (and other MongoDB Tools) will not attempt to validate the server certificates. This creates a vulnerability to expired mongod and mongos certificates as well as to foreign processes posing as valid mongod or mongos instances. If you only need to disable the validation of the hostname in the TLS/SSL certificates, see --sslAllowInvalidHostnames.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

--sslAllowInvalidHostnames

Disables the validation of the hostnames in TLS/SSL certificates. Allows mongodump to connect to MongoDB instances even if the hostname in their certificates do not match the specified hostname.

For more information about TLS/SSL and MongoDB, see Configure mongod and mongos for TLS/SSL and TLS/SSL Configuration for Clients .

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

Specifies a username with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the --password and --authenticationDatabase options.

Note

You cannot specify both --username and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

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

Specifies a password with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the --username and --authenticationDatabase options.

To prompt the user for the password, pass the --username option without --password or specify an empty string as the --password value, as in --password "" .

Note

You cannot specify both --password and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

--authenticationDatabase=<dbname>

Specifies the authentication database where the specified --username has been created. See Authentication Database.

Note

You cannot specify both --authenticationDatabase and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

If you do not specify an authentication database, mongodump assumes that the database specified to export holds the user’s credentials.

If you do not specify an authentication database or a database to export, mongodump assumes the admin database holds the user’s credentials.

--authenticationMechanism=<name>

Default: SCRAM-SHA-1

Specifies the authentication mechanism the mongodump instance uses to authenticate to the mongod or mongos.

Changed in version 4.0: MongoDB removes support for the deprecated MongoDB Challenge-Response (MONGODB-CR) authentication mechanism.

MongoDB adds support for SCRAM mechanism using the SHA-256 hash function (SCRAM-SHA-256).

Value Description
SCRAM-SHA-1 RFC 5802 standard Salted Challenge Response Authentication Mechanism using the SHA-1 hash function.
SCRAM-SHA-256 RFC 7677 standard Salted Challenge Response Authentication Mechanism using the SHA-256 hash function.
MONGODB-X509 MongoDB TLS/SSL certificate authentication.
GSSAPI (Kerberos) External authentication using Kerberos. This mechanism is available only in MongoDB Enterprise.
PLAIN (LDAP SASL) External authentication using LDAP. You can also use PLAIN for authenticating in-database users. PLAIN transmits passwords in plain text. This mechanism is available only in MongoDB Enterprise.

Note

You cannot specify both --authenticationMechanism and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

--gssapiServiceName

Specify the name of the service using GSSAPI/Kerberos. Only required if the service does not use the default name of mongodb.

This option is available only in MongoDB Enterprise.

--gssapiHostName

Specify the hostname of a service using GSSAPI/Kerberos. Only required if the hostname of a machine does not match the hostname resolved by DNS.

This option is available only in MongoDB Enterprise.

--db=<database>, -d=<database>

Specifies a database to backup. If you do not specify a database, mongodump copies all databases in this instance into the dump files.

Note

You cannot specify both --db and --uri.

Connections to MongoDB Atlas that use the +srv connection string option require the --uri option.

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

Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files.

--query=<json>, -q=<json>

Provides a JSON document as a query that optionally limits the documents included in the output of mongodump. To use the --query option, you must also specify the --collection option.

You must enclose the query document in single quotes ('{ ... }') to ensure that it does not interact with your shell environment.

Starting in MongoDB 4.2, the query must be in Extended JSON v2 format (either relaxed or canonical/strict mode), including enclosing the field names and operators in quotes. For example:

mongodump -d=test -c=records -q='{ "a": { "$gte": 3 }, "date": { "$lt": { "$date": "2016-01-01T00:00:00.000Z" } } }'
--queryFile=<path>

New in version 3.2.

Specifies the path to a file containing a JSON document as a query filter that limits the documents included in the output of mongodump. --queryFile enables you to create query filters that are too large to fit in your terminal’s buffer.

--readPreference=<string|document>

Default: primary

Specifies the read preference for mongodump. The --readPreference option can take:

  • A string if specifying only the read preference mode:

    --readPreference=secondary
    
  • A quote-enclosed document to specify the mode, the optional read preference tag sets, and the optional maxStalenessSeconds:

    --readPreference='{mode: "secondary", tagSets: [ { "region": "east" } ], maxStalenessSeconds: 120}'
    

    If specifying the maxStalenessSeconds, the value must be greater than or equal to 90.

    New in version 4.2.

mongodump defaults to primary read preference.

Starting in version 4.2, if the read preference is also included in the --uri connection string, the command-line --readPreference overrides the read preference specified in the URI string.

Warning

Using a read preference other than primary with a connection to a mongos may produce inconsistencies, duplicates, or result in missed documents.

--forceTableScan

By default, mongodump uses the _id index when scanning collections with that index is available (for example, views do not have any indexes). Specify --forceTableScan to direct mongodump to scan collection data without the use of the _id index.

--forceTableScan does not ensure a point-in-time snapshot. Use --oplog to create a point-in-time snapshot.

You cannot use --forceTableScan with the --query option.

--gzip

New in version 3.2.

Compresses the output. If mongodump outputs to the dump directory, the new feature compresses the individual files. The files have the suffix .gz.

If mongodump outputs to an archive file or the standard out stream, the new feature compresses the archive file or the data output to the stream.

--out=<path>, -o=<path>

Specifies the directory where mongodump will write BSON files for the dumped databases. By default, mongodump saves output files in a directory named dump in the current working directory.

To send the database dump to standard output, specify “-” instead of a path. Write to standard output if you want process the output before saving it, such as to use gzip to compress the dump. When writing standard output, mongodump does not write the metadata that writes in a <dbname>.metadata.json file when writing to files directly.

You cannot use the --archive option with the --out option.

--archive=<file>

New in version 3.2.

Writes the output to a specified archive file or, if the archive file is unspecified, writes to the standard output (stdout).

  • To output the dump to an archive file, run mongodump with the --archive option and the archive filename.

    mongodump --archive=<file>
    
  • To output the dump to the standard output stream in order to pipe to another process, run mongodump with the --archive option but omit the filename.

    mongodump --archive
    

You cannot use the --archive option with the --out option.

--oplog

Creates a file named oplog.bson as part of the mongodump output. The oplog.bson file, located in the top level of the output directory, contains oplog entries that occur during the mongodump operation. This file provides an effective point-in-time snapshot of the state of a mongod instance. To restore to a specific point-in-time backup, use the output created with this option in conjunction with mongorestore --oplogReplay.

Without --oplog, if there are write operations during the dump operation, the dump will not reflect a single moment in time. Changes made to the database during the update process can affect the output of the backup.

Important

A mongodump running with --oplog fails if a client issues any of the listed operations during the dump process.

--oplog has no effect when running mongodump against a mongos instance to dump the entire contents of a sharded cluster. However, you can use --oplog to dump individual shards.

--oplog only works against nodes that maintain an oplog. This includes all members of a replica set.

--oplog does not dump the oplog collection.

Note

To use mongodump with --oplog, you must create a full dump of a replica set member. mongodump with --oplog fails if you use any of the following options to limit the data to be dumped:

--dumpDbUsersAndRoles

Includes user and role definitions in the database’s dump directory when performing mongodump on a specific database. This option applies only when you specify a database in the --db option. MongoDB always includes user and role definitions when mongodump applies to an entire instance and not just a specific database.

--excludeCollection=<string>

Excludes the specified collection from the mongodump output. To exclude multiple collections, specify the --excludeCollection multiple times.

--excludeCollectionsWithPrefix=<string>

Excludes all collections with a specified prefix from the mongodump outputs. To specify multiple prefixes, specify the --excludeCollectionsWithPrefix multiple times.

--numParallelCollections=<int>, -j=<int>

Default: 4

Number of collections mongodump should export in parallel.

--viewsAsCollections

New in version 3.4.

When specified, mongodump exports read-only views as collections. For each view, mongodump will produce a BSON file containing the documents in the view. If you mongorestore the produced BSON file, the view will be restored as a collection.

If you do not include --viewsAsCollections, mongodump captures each view’s metadata. If you include a view’s metadata file in a mongorestore operation, the view is recreated.

Examples

mongodump a Collection

The following operation creates a dump file that contains only the collection named records in the database named test. In this case the database is running on the local interface on port 27017:

mongodump  --db=test --collection=records

mongodump a Database Excluding Specified Collections

The following operation dumps all collections in the test database except for users and salaries:

mongodump  --db=test --excludeCollection=users --excludeCollection=salaries

mongodump with Access Control

In the next example, mongodump creates a database dump located at /opt/backup/mongodump-2011-10-24, from a database running on port 37017 on the host mongodb1.example.net and authenticating using the username user as follows:

mongodump --host=mongodb1.example.net --port=37017 --username=user --authenticationDatabase=admin --out=/opt/backup/mongodump-2011-10-24

If you do not include the --password, mongodump prompts the user for the password.

Output to an Archive File

New in version 3.2.

To output the dump to an archive file, run mongodump with the --archive option and the archive filename. For example, the following operation creates a file test.20150715.archive that contains the dump of the test database.

mongodump --archive=test.20150715.archive --db=test

Output an Archive to Standard Output

New in version 3.2.

To output the archive to the standard output stream in order to pipe to another process, run mongodump with the archive option but omit the filename:

mongodump --archive --db=test --port=27017 | mongorestore --archive --port=27018

Note

You cannot use the --archive option with the --out option.

Compress the Output

To compress the files in the output dump directory, run mongodump with the new --gzip option. For example, the following operation outputs compressed files into the default dump directory.

mongodump --gzip --db=test

To compress the archive file output by mongodump, use the --gzip option in conjunction with the --archive option, specifying the name of the compressed file.

mongodump --archive=test.20150715.gz --gzip --db=test

Copy/Clone a Database

Starting in version 4.2, MongoDB removes the deprecated copydb command and clone command.

As an alternative, users can use mongodump and mongorestore (with the mongorestore options --nsFrom and --nsTo).

For example, to copy the test database from a local instance running on the default port 27017 to the examples database on the same instance, you can:

  1. Use mongodump to dump the test database to an archive mongodump-test-db:

    mongodump --archive="mongodump-test-db" --db=test
    
  2. Use mongorestore with --nsFrom and --nsTo to restore (with database name change) from the archive:

    mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'
    

Tip

Include additional options as necessary, such as to specify the uri or host, username, password and authentication database.

Alternatively, instead of using an archive file, you can mongodump the test database to the standard output stream and pipe into mongorestore:

mongodump --archive --db=test | mongorestore --archive  --nsFrom='test.*' --nsTo='examples.*'
←   mongos.exe mongorestore  →