On this page
mongodump
On this page
macOS Sierra and Go 1.6 Incompatibility
Users running on macOS Sierra require the 3.2.10 or newer version of mongodump.
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.
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. However, the use of mongodump and mongorestore as a backup strategy can be problematic for sharded clusters and replica sets.
Run mongodump from the system command line, not the mongo shell.
For an overview of mongodump in conjunction with mongorestore part of a backup and recovery strategy, see Back Up and Restore with MongoDB Tools.
Behavior
Data Exclusion
mongodump excludes the content of the local database in its output.
mongodump only captures the documents in the database in its backup data 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.
Read Preference
Replica Sets
Changed in version 3.2.0: The choice of target or targets for the --host parameter affects the read preference of mongodump when connecting to a replica set.
If the string passed to
--hostis prefixed by the replica set name,mongodumpreads from theprimaryreplica set member by default. For example:--host "replSet/rep1.example.net:27017,rep2.example.net:27017,rep3.example.net:27017"If the string passed to
--hostcontains a list ofmongodinstances, but does not include the replica set name as a prefix to the host string,mongodumpreads from thenearestnode by default. For example:--host "rep1.example.net:27017,rep2.example.net:27017,rep3.example.net:27017"
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.
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.
Changed in version 3.2.1: The backup role provides additional privileges to back up the system.profile collections that exist when running with database profiling. Previously, users required an additional read access on this collection.
Options
Changed in version 3.0.0: mongodump removed the --dbpath as well as related --directoryperdb and --journal options. To use mongodump, you must run mongodump against a running mongod or mongos instance as appropriate.
--verbose,-v-
Increases the amount of internal reporting returned on standard output or in log files. Increase the verbosity with the
-vform 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
--uri<connectionString>-
New in version 3.4.6.
Specify a resolvable URI connection string to connect to the MongoDB deployment.
--uri "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"For more information on the components of the connection string, see the Connection String URI Format documentation.
Important
The following command-line options cannot be used in conjunction with
--urioption:--host--port--db--username--password(if the URI connection string also includes the password)--authenticationDatabase--authenticationMechanism
Instead, specify these options as part of your
--uriconnection string.
--host<hostname><:port>,-h<hostname><:port>-
Default: localhost:27017
Specifies a resolvable hostname for the
mongodto which to connect. By default, the mongodump attempts to connect to a MongoDB instance running on the localhost on port number27017.To connect to a replica set, specify the
replSetNameand 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>Changed in version 3.0.0: 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>]).
--port<port>-
Default: 27017
Specifies the TCP port on which the MongoDB instance listens for client connections.
--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
--ipv6to use IPv6. In MongoDB 3.0 and later, IPv6 is always enabled.
--ssl