mongodump

macOS Sierra and Go 1.6 Incompatibility

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

Synopsis

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

Availability

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

The tools package is also available from theMongoDB Download Center,either as a separate tools download, or contained within theTGZ 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 DownloadCenter, you may want to update your PATH environmentvariable to include the directory where you installed these tools.See the installation guidefor your platform for more information.

Usage in Backup Strategy

Standalones/Replica Sets

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

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

Sharded Cluster

mongodump and mongorestorecannot be part of a backup strategy for 4.2+ sharded clustersthat have sharded transactions in progress as these tools cannotguarantee a atomicity guarantees of data across the shards.

For 4.2+ sharded clusters with in-progress sharded transactions, forcoordinated backup and restore processes that maintain the atomicityguarantees of transactions across shards, see:

Syntax

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

  1. mongodump [options]

Connect to a MongoDB Instance

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

  1. mongodump

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

  1. mongodump --uri="mongodb://mongodb0.example.com:27017" [additional options]
  • Specify the hostname and port in the —host:
  1. mongodump --host="mongodb0.example.com:27017" [additional options]
  1. 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:

  1. 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:
  1. mongodump --host="myReplicaSetName/mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com" [additional options]

By default, mongodump reads from the primary of thereplica set. To override the default, you can specify the readpreference:

  1. 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 thereadPreferenceTags option:

  1. 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-lineoption. The command-line option takes a string if specifying only the read preference mode:
  1. 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 tagsets, and the optionalmaxStalenessSeconds:

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

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

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

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

If specifying the read preference tags, include thereadPreferenceTags option:

  1. 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-lineoption. The command-line option takes a string if specifying only the read preference mode:
  1. 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 tagsets, and the optionalmaxStalenessSeconds:

  1. 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 preferenceprimary. To override the default, you can specify theread preference in the—readPreference command-lineoption or in the —uri connection string.

Starting in version 4.2, if you specify read preference in the URIstring and the —readPreferenceoption, the —readPreferencevalue 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 thedatabase and does not include index data. mongorestoreor mongod must then rebuild the indexes after restoringdata.

Changed in version 3.4: MongoDB 3.4 added support forread-only views. By default,mongodump only captures a view’s metadata: it does notcreate a binary export of the documents included in the view. Tocapture the documents in a view use —viewsAsCollections.

Metadata Format

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

Tip

If general, use corresponding versions of mongodumpand mongorestore. That is, to restore data filescreated with a specific version of mongodump, use thecorresponding version of mongorestore.

Overwrite Files

mongodump overwrites output files if they exist in thebackup data folder. Before running the mongodump commandmultiple times, either ensure that you no longer need the files in theoutput folder (the default is the dump/ folder) or rename thefolders or files.

Data Compression Handling

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

Working Set

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

FIPS

Starting in version 4.2, MongoDB removes the —sslFIPSModeoption for mongodump. mongodumpwill use FIPS compliant connections tomongod/mongos if themongod/mongos instances areconfigured to use FIPS mode.

Required Access

To run mongodump against a MongoDB deployment that hasaccess control enabled, you must haveprivileges that grant find action for each database toback up. The built-in backup role provides the requiredprivileges to perform backup of any and all databases.

Changed in version 3.2.1: The backup role provides additional privileges to backup the system.profilecollection that exists when running with database profiling. Previously, users requiredread access on this collection.

Options

Changed in version 3.0.0: mongodump removed the —dbpath as well as related—directoryperdb and —journal options. To usemongodump, you must run mongodump against a runningmongod or mongos instance as appropriate.

  • mongodump
  • —help
  • Returns information on the options and use of mongodump.
  • —verbose, -v
  • Increases the amount of internal reporting returned on standard outputor in log files. Increase the verbosity with the -v form byincluding the option multiple times, (e.g. -vvvvv.)
  • —quiet
  • Runs mongodump in a quiet mode that attempts to limit the amountof 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 URIconnection string (enclose in quotes) to connect to the MongoDB deployment.

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

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

Note

For TLS/SSL options, use the command-line options instead of theURI options for TLS/SSL (Available starting in4.2).

Important

The following command-line options cannot be used in conjunctionwith —uri option:

  • —host=<hostname><:port>, -h=<hostname><:port>
  • Default: localhost:27017

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

To connect to a replica set, specify thereplSetName and a seed list of set members, as inthe following:

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

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

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

  1. --host=<hostname1><:port>

Changed in version 3.0.0: If you use IPv6 and use the <address>:<port> format, you mustenclose the portion of an address and port combination inbrackets (e.g. [<address>]).

Note

You cannot specify both —host and —uri.

  • —port=<port>
  • Default: 27017

Specifies the TCP port on which the MongoDB instance listens forclient connections.

Note

You cannot specify both —port and —uri.

  • —ipv6
  • Removed in version 3.0.

Enables IPv6 support and allows mongodump to connect to theMongoDB instance using an IPv6 network. Prior to MongoDB 3.0, youhad to specify —ipv6 to use IPv6. In MongoDB 3.0 and later, IPv6is always enabled.

  • —ssl

New in version 2.6.

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

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

  • —sslCAFile=<filename>

New in version 2.6.

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

Starting in version 3.4, if —tlsCAFile/net.tls.CAFile (ortheir aliases —sslCAFile/net.ssl.CAFile) is not specifiedand you are not using x.509 authentication, the system-wide CAcertificate store will be used when connecting to an TLS/SSL-enabledserver.

To use x.509 authentication, —tlsCAFile or net.tls.CAFilemust 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) tomongod and mongos, if the mongodump runs without the—sslCAFile, mongodump will not attemptto validate the server certificates. This creates a vulnerabilityto expired mongod and mongos certificates aswell as to foreign processes posing as valid mongod ormongos instances. Ensure that you always specify theCA file to validate the server certificates in cases whereintrusion is a possibility.

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

  • —sslPEMKeyFile=<filename>

New in version 2.6.

Specifies the .pem file that contains both the TLS/SSL certificateand key. Specify the file name of the .pem file using relativeor absolute paths.

This option is required when using the —ssl option to connectto a mongod or mongos that hasCAFile enabled withoutallowConnectionsWithoutCertificates.

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

  • —sslPEMKeyPassword=<value>

New in version 2.6.

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

If the private key in the PEM file is encrypted and you do not specifythe —sslPEMKeyPassword option, the mongodump will prompt for a passphrase. SeeTLS/SSL Certificate Passphrase.

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

  • —sslCRLFile=<filename>

New in version 2.6.

Specifies the .pem file that contains the Certificate RevocationList. Specify the file name of the .pem file using relative orabsolute paths.

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

  • —sslAllowInvalidCertificates

New in version 2.6.

Bypasses the validation checks for server certificates and allowsthe use of invalid certificates. When using theallowInvalidCertificates setting, MongoDB logs as awarning the use of the invalid certificate.

Starting in MongoDB 4.0, if you specify—sslAllowInvalidCertificates ornet.ssl.allowInvalidCertificates: true (or in MongoDB 4.2, thealias —tlsAllowInvalidateCertificates ornet.tls.allowInvalidCertificates: true) when using x.509authentication, an invalid certificate is only sufficient toestablish a TLS/SSL connection but is insufficient forauthentication.

Warning

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

If the mongo shell (and otherMongoDB Tools) runs with the—sslAllowInvalidCertificates option, themongo shell (and otherMongoDB Tools) will not attempt to validatethe server certificates. This creates a vulnerability to expiredmongod and mongos certificates aswell as to foreign processes posing as validmongod or mongos instances. If youonly need to disable the validation of the hostname in theTLS/SSL certificates, see —sslAllowInvalidHostnames.

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

  • —sslAllowInvalidHostnames

New in version 3.0.

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

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

  • —username=<username>, -u=<username>
  • Specifies a username with which to authenticate to a MongoDB databasethat uses authentication. Use in conjunction with the —password and—authenticationDatabase options.

Note

You cannot specify both —username and —uri.

  • —password=<password>, -p=<password>
  • Specifies a password with which to authenticate to a MongoDB databasethat uses authentication. Use in conjunction with the —username and—authenticationDatabase options.

Changed in version 3.0.2: To prompt the userfor 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.

Note

You cannot specify both —authenticationDatabase and —uri.

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

If you do not specify an authentication database or a database toexport, mongodump assumes the admin database holds the user’scredentials.

  • —authenticationMechanism=<name>
  • Default: SCRAM-SHA-1

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

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

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

ValueDescriptionSCRAM-SHA-1RFC 5802 standardSalted Challenge Response Authentication Mechanism using the SHA-1hash function.SCRAM-SHA-256RFC 7677 standardSalted Challenge Response Authentication Mechanism using the SHA-256hash function.

Requires featureCompatibilityVersion set to 4.0.

New in version 4.0.

MONGODB-X509MongoDB TLS/SSL certificate authentication.GSSAPI (Kerberos)External authentication using Kerberos. This mechanism isavailable only in MongoDB Enterprise.PLAIN (LDAP SASL)External authentication using LDAP. You can also use PLAINfor authenticating in-database users. PLAIN transmitspasswords in plain text. This mechanism is available only inMongoDB Enterprise.

Note

You cannot specify both —authenticationMechanism and —uri.

  • —gssapiServiceName

New in version 2.6.

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

This option is available only in MongoDB Enterprise.

  • —gssapiHostName

New in version 2.6.

Specify the hostname of a service using GSSAPI/Kerberos. Only required if the hostname of a machine doesnot 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 dumpfiles.

Note

You cannot specify both —db and —uri.

  • —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 instanceto the dump files.
  • —query=<json>, -q=<json>
  • Provides a JSON document as a query that optionally limitsthe documents included in the output of mongodump. Touse the —query option, you must also specify the—collection option.

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

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

  1. 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 queryfilter that limits the documents included in the output ofmongodump. —queryFile enables you to create query filters thatare too large to fit in your terminal’s buffer.

  • —readPreference=<string|document>
  • Default: primary

Specifies the read preference formongodump. The —readPreference option can take:

  • A string if specifying only the read preference mode:
  1. --readPreference=secondary
  1. --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 primaryread preference.

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

Warning

Using a read preference other thanprimary with a connection to a mongos may produceinconsistencies, duplicates, or result in missed documents.

  • —forceTableScan
  • By default, mongodump uses the _id index when scanningcollections with that index is available (e.g.Views do not have any indexes). Specify —forceTableScanto 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 dumpdirectory, the new feature compresses the individual files. The fileshave the suffix .gz.

If mongodump outputs to an archive file or the standardout stream, the new feature compresses the archive file or the dataoutput to the stream.

  • —out=<path>, -o=<path>
  • Specifies the directory where mongodump will writeBSON files for the dumped databases. By default,mongodump saves output files in a directory nameddump in the current working directory.

To send the database dump to standard output, specify “-” instead ofa path. Write to standard output if you want process the output beforesaving it, such as to use gzip to compress the dump. When writingstandard output, mongodump does not write the metadata thatwrites in a <dbname>.metadata.json file when writing to filesdirectly.

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 archivefile is unspecified, writes to the standard output (stdout).

  • To output the dump to an archive file, runmongodump with the —archive option and the archive filename.
  1. mongodump --archive=<file>
  • To output the dump to the standard output stream in order to pipeto another process, run mongodump with the—archive option but omit thefilename.
  1. mongodump --archive

You cannot use the —archive optionwith the —out option.

  • —oplog
  • Creates a file named oplog.bson as part of themongodump output. The oplog.bson file, located inthe top level of the output directory, contains oplog entries thatoccur during the mongodump operation. This file providesan effective point-in-time snapshot of the state of amongod instance. To restore to a specific point-in-timebackup, use the output created with this option in conjunction withmongorestore —oplogReplay.

Without —oplog, if there are write operations during the dumpoperation, the dump will not reflect a single moment in time. Changesmade to the database during the update process can affect the output ofthe backup.

—oplog has no effect when running mongodumpagainst a mongos instance to dump the entire contents of asharded cluster. However, you can use —oplog to dumpindividual shards.

—oplog only works against nodes that maintain anoplog. 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 ofa replica set member. mongodump with —oplog failsif you use any of the following options to limit the data to be dumped:

See also

mongorestore —oplogReplay

  • —dumpDbUsersAndRoles
  • Includes user and role definitions in the database’s dump directorywhen performing mongodump on a specific database. Thisoption applies only when you specify a database in the—db option. MongoDB always includes user and roledefinitions when mongodump applies to an entire instanceand not just a specific database.
  • —excludeCollection=<string>

New in version 3.0.

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

  • —excludeCollectionsWithPrefix=<string>

New in version 3.0.

Excludes all collections with a specified prefix from the mongodumpoutputs. To specify multiple prefixes, specify the —excludeCollectionsWithPrefix multipletimes.

  • —numParallelCollections=<int>, -j=<int>
  • Default: 4

Number of collections mongodump should exportin parallel.

  • —viewsAsCollections

New in version 3.4.

When specified, mongodump exports read-only views as collections. For each view, mongodump willproduce a BSON file containing the documents in the view. If youmongorestore the produced BSON file, the view will berestored as a collection.

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

Examples

mongodump a Collection

The following operation creates a dump file that contains only thecollection named records in the database named test. Inthis case the database is running on the local interface on port27017:

  1. mongodump --db=test --collection=records

mongodump a Database Excluding Specified Collections

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

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

mongodump with Access Control

In the next example, mongodump creates a database dumplocated at /opt/backup/mongodump-2011-10-24, from a databaserunning on port 37017 on the host mongodb1.example.net andauthenticating using the username user as follows:

  1. 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 followingoperation creates a file test.20150715.archive that contains the dumpof the test database.

  1. 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 toanother process, run mongodump with the archiveoption but omit the filename:

  1. 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, runmongodump with the new —gzip option. For example,the following operation outputs compressed files into the defaultdump directory.

  1. mongodump --gzip --db=test

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

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

Copy/Clone a Database

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

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

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

  • Use mongodump to dump the test database toan archive mongodump-test-db:
  1. mongodump --archive="mongodump-test-db" --db=test
  1. mongorestore --archive="mongodump-test-db" --nsFrom='test.*' --nsTo='examples.*'

Tip

Include additional options as necessary, such as to specifythe uri or host, username, password and authenticationdatabase.

Alternatively, instead of using an archive file, you canmongodump the test database to the standardoutput stream and pipe into mongorestore:

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