> This page location: /docs.md > /docs/tools-and-connectors.md > /docs/database-tools.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: connect-to-an-instance, connect-to-a-replica-set, connect-to-a-sharded-cluster
-->

# `mongodump`

MongoDB Command Line Database Tool binaries are not supported or tested for use with non-genuine MongoDB deployments. While the tools may work on these deployments, compatibility is not guaranteed.

## Definition

`mongodump` is a utility that creates a binary export of a database's contents. [`mongorestore`](https://www.mongodb.com/docs/database-tools/mongorestore.md#mongodb-binary-bin.mongorestore) allows you to import data that was exported from `mongodump`.

`mongodump` can export data from:

- Standalone deployments

- Replica sets

- Sharded clusters

- Flex clusters

You can use the MongoDB Database Tools to migrate from a self-hosted deployment to [MongoDB Atlas](https://www.mongodb.com/docs/atlas). MongoDB Atlas is the fully managed service for MongoDB deployments in the cloud. To learn more, see [Seed with mongorestore.](https://www.mongodb.com/docs/atlas/import/mongorestore/)

To learn all the ways you can migrate to MongoDB Atlas, see [Migrate or Import Data.](https://www.mongodb.com/docs/atlas/import/)

`mongodump` can connect to [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances.

You can restore the BSON files generated from `mongodump` into MongoDB deployments running the same major version or feature compatibility version as the source deployment.

Run `mongodump` from the system command line, not the [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell.

**Note:**

If you are archiving stale data to save on storage costs, consider [Online Archive](https://www.mongodb.com/docs/atlas/online-archive/manage-online-archive/) in [MongoDB Atlas](https://www.mongodb.com/cloud). Online Archive features data tiering, which automatically archives infrequently accessed data to fully-managed S3 buckets for availability.

Online Archive isn't supported on Atlas Infinite Database clusters. See [Public Preview Availability.](https://www.mongodb.com/docs/atlas/infinite/atlas-infinite-landing/#public-preview-availability)

`mongodump` dumps:

- Collection documents, metadata, and options.

- Index definitions.

- Writes that occur during the export, if run with the `mongodump` [`--oplog`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--oplog) option.

`mongodump` dumps data to a directory or a binary archive file.

**Important:**

You can't use `mongodump` with a collection that uses Queryable Encryption or client-side field level encryption (CSFLE).

### Dump Data to a Directory

Example `mongodump` directory dump structure and files:

```none
dump
├── easternSalesDatabase
│    ├── sales.bson
│    ├── sales.metadata.json
│    └── salesByMonthView.metadata.json
├── westernSalesDatabase
│    ├── sales.bson
│    ├── sales.metadata.json
│    └── salesByMonthView.metadata.json
└── oplog.bson
```

For a directory dump, `mongodump` creates:

- A root directory with the default name `dump`. You can set the name with the `mongodump` [`--out`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--out) option.

- A subdirectory in the root directory for each database. For example, if a database name is `easternSalesDatabase`, the subdirectory name is also `easternSalesDatabase`.

- A BSON file with documents for each collection. For example, if a collection name is `sales`, the BSON file is `sales.bson`.

- A metadata JSON file for each collection in each database directory. For example, a metadata `sales.metadata.json` file. The file contains a document with the exported collection metadata, options, and indexes.

- A metadata JSON file for each view. For example, a metadata `salesByMonthView.metadata.json` file. A view doesn't have a BSON file.

- An optional [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) `oplog.bson` file, located in the root directory, which contains write operations that occurred during the `mongodump` run. To output an `oplog.bson` file, use the `mongodump` [`--oplog`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--oplog) option.

If you use the `mongodump` [`--gzip`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--gzip) option, the BSON files and JSON metadata files are compressed. The compressed exported files have `bson.gz` and `metadata.json.gz` at the end of the names.

### Dump Data to a Binary Archive File

To dump data to a binary archive file, use the `mongodump` [`--archive`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--archive) option. `mongodump` creates a binary file that contains the archived data.

If you run `mongodump` with the [`--oplog`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--oplog) option, the archive includes the oplog entries.

## Security Considerations

Do not pass connection options such as `--uri` or `--host` from an untrusted source to `mongodump`. Untrusted connection information can expose information from the host that runs the tool or direct the tool to an attacker-controlled cluster.

## Syntax

`mongodump` syntax:

```sh
mongodump <options> <connection-string>
```

### Connect to an 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:

```sh
mongodump
```

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

- Specify the hostname and port in the [`--uri connection string`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri) option:

  ```sh
  mongodump --uri="mongodb://mongodb0.example.com:27017" [additional options]
  ```

- Specify the hostname and port in the [`--host`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--host) option:

  ```sh
  mongodump --host="mongodb0.example.com:27017"  [additional options]
  ```

- Specify the hostname and port in the [`--host`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--host) and [`--port`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--port) options:

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

## Options

Returns information on the options and use of `mongodump`.

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. For example: `-vvvvv`.

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

This option suppresses:

- Output from [database commands](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-database-command)

- Replication activity

- Connection accepted and closed events

- All logs, including error messages, except for those that occur when parsing options

Returns the `mongodump` release number.

**New in version 100.3.0**

Specifies the full path to a YAML configuration file that contains sensitive values for the following `mongodump` options:

- [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password)

- [`--uri`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri)

- [`--sslPEMKeyPassword`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslPEMKeyPassword)

This is the recommended way to specify a password to `mongodump`, aside from specifying it through a password prompt. You can use any combination of the arguments in the file.

The configuration file takes the following form:

```sh
password: <password>
uri: mongodb://mongodb0.example.com:27017
sslPEMKeyPassword: <password>
```

If you specify the `password` option without specifying `uri`, you can specify the other components of the connection string by using `mongodump` command line options, such as [`--username`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--username) and [`--host`.](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--host)

Be sure to secure this file with appropriate filesystem permissions.

**Important:**

When using the `--config` option, keep the following limitations and behaviors in mind:

- If you provide the `password` field and provide a connection string in the `uri` field with a conflicting password, `mongorestore` throws an error.

- If you specify a configuration file with `--config` and also use the [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password), [`--uri`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri), or [`--sslPEMKeyPassword`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslPEMKeyPassword) `mongodump` command line options, the command line option overrides the corresponding configuration file option.

Specifies the resolvable [URI connection string](https://www.mongodb.com/docs/manual/reference/connection-string/) of the MongoDB deployment, enclosed in quotes:

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

Starting with version `100.0` of `mongodump`, the connection string may alternatively be provided as a positional parameter, without using the [`--uri`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri) option:

```none
mongodump mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
```

As a positional parameter, the connection string may be specified at any point on the command line, as long as it begins with either `mongodb://` or `mongodb+srv://`. For example:

```none
mongodump --username joe --password secret1 mongodb://mongodb0.example.com:27017 --ssl
```

Only one connection string can be provided. Attempting to include more than one, whether using the [`--uri`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri) option or as a positional argument, will result in an error.

For information on the components of the connection string, see the [Connection String URI Format](https://www.mongodb.com/docs/manual/reference/connection-string/) documentation.

**Note:**

Some components in the [`connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri) may alternatively be specified using their own explicit command-line options, such as [`--username`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--username) and [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password). Providing a connection string while also using an explicit option and specifying conflicting information will result in an error.

**Note:**

If using `mongodump` on Ubuntu 18.04, you may experience a `cannot unmarshal DNS` error message when using [SRV connection strings](https://www.mongodb.com/docs/manual/reference/connection-string-formats.md#std-label-connections-dns-seedlist) (in the form `mongodb+srv://`) with the [`--uri`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri) option. If so, use one of the following options instead:

- the [`--uri`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri) option with a [non-SRV connection string](https://www.mongodb.com/docs/manual/reference/connection-string-formats.md#std-label-connections-standard-connection-string-format) (in the form `mongodb://`)

- the [`--host`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--host) option to specify the host to connect to directly

**Warning:**

On some systems, a password provided in a connection string with the [`--uri`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri) option may be visible to system status programs such as `ps` that may be invoked by other users. Consider instead:

- omitting the password in the connection string to receive an interactive password prompt, or

- using the [`--config`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--config) option to specify a configuration file containing the password.

*Default*: localhost:27017

Specifies the resolvable hostname of the MongoDB deployment. By default, `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`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-replication.replSetName) and a seed list of set members, as in the following:

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

When specifying the replica set list format, `mongodump` always connects to the [primary.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary)

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

```none
--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. For example: `[<address>]`.

Alternatively, you can also specify the hostname directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--host`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--host) and specifying conflicting information will result in an error.

*Default*: 27017

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

Alternatively, you can also specify the port directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--port`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--port) and specifying conflicting information will result in an error.

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

Alternatively, you can also configure TLS/SSL support directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--ssl`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--ssl) and specifying conflicting information will result in an error.

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.

Alternatively, you can also specify the `.pem` file directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--sslCAFile`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslCAFile) and specifying conflicting information will result in an error.

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`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-net.tls.CAFile) enabled *without* [`allowConnectionsWithoutCertificates`.](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-net.tls.allowConnectionsWithoutCertificates)

Alternatively, you can also specify the `.pem` file directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--sslPEMKeyFile`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslPEMKeyFile) and specifying conflicting information will result in an error.

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, `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, `mongodump` will prompt for a passphrase. See [TLS/SSL Certificate Passphrase.](https://www.mongodb.com/docs/manual/tutorial/configure-ssl.md#std-label-ssl-certificate-password)

Alternatively, you can also specify the password directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--sslPEMKeyPassword`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslPEMKeyPassword) and specifying conflicting information will result in an error.

**Warning:**

On some systems, a password provided directly using the [`--sslPEMKeyPassword`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslPEMKeyPassword) option may be visible to system status programs such as `ps` that may be invoked by other users. Consider using the [`--config`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--config) option to specify a configuration file containing the password instead.

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

Bypasses the validation checks for server certificates and allows the use of invalid certificates. When using the [`allowInvalidCertificates`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-net.tls.allowInvalidCertificates) setting, MongoDB logs as a warning the use of the invalid certificate.

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

Connecting to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance without validating server certificates is a potential security risk. If you only need to disable the validation of the hostname in the TLS/SSL certificates, see `--sslAllowInvalidHostnames`.

Alternatively, you can also disable certificate validation directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--sslAllowInvalidCertificates`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslAllowInvalidCertificates) and specifying conflicting information will result in an error.

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.

Alternatively, you can also disable hostname validation directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--sslAllowInvalidHostnames`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--sslAllowInvalidHostnames) and specifying conflicting information will result in an error.

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

Alternatively, you can also specify the username directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--username`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--username) and specifying conflicting information will result in an error.

If connecting to a [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) cluster using the `MONGODB-AWS` [`authentication mechanism`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--authenticationMechanism), you can specify your AWS access key ID in:

- this field,

- the [`connection string`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri), or

- the `AWS_ACCESS_KEY_ID` environment variable.

See [Connect to a MongoDB Atlas Cluster using AWS IAM Credentials](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-examples.md#std-label-mongodump-example-connect-using-aws-iam) for an example of each.

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

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

Alternatively, you can also specify the password directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password) and specifying conflicting information will result in an error.

If connecting to a [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) cluster using the `MONGODB-AWS` [`authentication mechanism`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--authenticationMechanism), you can specify your AWS secret access key in:

- this field,

- the [`connection string`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri), or

- the `AWS_SECRET_ACCESS_KEY` environment variable.

See [Connect to a MongoDB Atlas Cluster using AWS IAM Credentials](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-examples.md#std-label-mongodump-example-connect-using-aws-iam) for an example of each.

**Warning:**

On some systems, a password provided directly using the [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password) option may be visible to system status programs such as `ps` that may be invoked by other users. Consider instead:

- omitting the [`--password`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--password) option to receive an interactive password prompt, or

- using the [`--config`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--config) option to specify a configuration file containing the password.

If connecting to a [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) cluster using the `MONGODB-AWS` [`authentication mechanism`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--authenticationMechanism), and using session tokens in addition to your AWS access key ID and secret access key, you can specify your AWS session token in:

- this field,

- the `AWS_SESSION_TOKEN` [`authMechanismProperties`](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#mongodb-urioption-urioption.authMechanismProperties) parameter to the [`connection string`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri), or

- the `AWS_SESSION_TOKEN` environment variable.

See [Connect to a MongoDB Atlas Cluster using AWS IAM Credentials](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-examples.md#std-label-mongodump-example-connect-using-aws-iam) for an example of each.

Only valid when using the `MONGODB-AWS` [`authentication mechanism`.](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--authenticationMechanism)

Specifies the authentication database where the specified `--username <mongodump --username>` has been created. See [Authentication Database.](https://www.mongodb.com/docs/manual/core/security-users.md#std-label-user-authentication-database)

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.

If you use the [GSSAPI](https://www.mongodb.com/docs/manual/core/authentication.md#std-label-security-auth-kerberos) (Kerberos), [PLAIN](https://www.mongodb.com/docs/manual/core/authentication.md#std-label-security-auth-ldap) (LDAP SASL), or `MONGODB-AWS` [`authentication mechanisms`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--authenticationMechanism), you must set [`--authenticationDatabase`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--authenticationDatabase) to `$external`.

Alternatively, you can also specify the authentication database directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--authenticationDatabase`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--authenticationDatabase) and specifying conflicting information will result in an error.

*Default*: SCRAM-SHA-1

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

**Changed in version 100.1.0**

Starting in version `100.1.0`, `mongodump` adds support for the `MONGODB-AWS` authentication mechanism when connecting to a [MongoDB Atlas](https://www.mongodb.com/docs/atlas/) cluster.

| Value | Description |
| --- | --- |
| [SCRAM-SHA-1](https://www.mongodb.com/docs/manual/core/security-scram.md#std-label-authentication-scram-sha-1) | [RFC 5802](https://tools.ietf.org/html/rfc5802) standard Salted Challenge Response Authentication Mechanism using the SHA-1 hash function. |
| [SCRAM-SHA-256](https://www.mongodb.com/docs/manual/core/security-scram.md#std-label-authentication-scram-sha-256) | [RFC 7677](https://tools.ietf.org/html/rfc7677) standard Salted Challenge Response Authentication Mechanism using the SHA-256 hash function. Requires featureCompatibilityVersion set to `4.0`. |
| [MONGODB-X.509](https://www.mongodb.com/docs/manual/core/security-x.509.md#std-label-security-auth-x509) | MongoDB TLS/SSL certificate authentication. |
| `MONGODB-AWS` | External authentication using AWS IAM credentials for use in connecting to a [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) cluster. See [Connect to a MongoDB Atlas Cluster using AWS IAM Credentials](https://www.mongodb.com/docs/database-tools/mongotop/mongotop-examples.md#std-label-mongotop-example-connect-using-aws-iam). **New in version 100.1.0** |
| [GSSAPI](https://www.mongodb.com/docs/manual/core/authentication.md#std-label-security-auth-kerberos) (Kerberos) | External authentication using Kerberos. This mechanism is available only in [MongoDB Enterprise.](http://www.mongodb.com/products/mongodb-enterprise-advanced) |
| [PLAIN](https://www.mongodb.com/docs/manual/core/authentication.md#std-label-security-auth-ldap) (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.](http://www.mongodb.com/products/mongodb-enterprise-advanced) |

Alternatively, you can also specify the authentication mechanism directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--uri). Providing a connection string while also using [`--authenticationMechanism`](https://www.mongodb.com/docs/database-tools/mongotop.md#std-option-mongotop.--authenticationMechanism) and specifying conflicting information will result in an error.

Specify the name of the service using [GSSAPI/Kerberos](https://www.mongodb.com/docs/manual/core/kerberos/). Only required if the service does not use the default name of `mongodb`.

This option is available only in MongoDB Enterprise.

Alternatively, you can also specify the service name directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri). Providing a connection string while also using [`--gssapiServiceName`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--gssapiServiceName) and specifying conflicting information will result in an error.

Specify the hostname of a service using `GSSAPI/Kerberos </core/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.

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

Alternatively, you can also specify the database directly in the [`URI connection string`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--uri). Providing a connection string while also using [`--db`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--db) and specifying conflicting information will result in an error.

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.

Provides a [JSON document](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-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 <mongodump --collection>` option.

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

The query must be in [Extended JSON v2 format (either relaxed or canonical/strict mode)](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/), including enclosing the field names and operators in quotes. For example:

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

To use [`$regex`](https://www.mongodb.com/docs/manual/reference/operator/query/regex.md#mongodb-query-op.-regex) with `mongodump`, use the following syntax:

```sh
mongodump -d=sample_mflix -c=movies -q='{ "year": { "$regex": "20" } }'
```

Starting in MongoDB 9.0, the server matches dotted field paths to `null` differently when an intermediate component of the path is an array of scalar values. This change affects the [`$eq`](https://www.mongodb.com/docs/manual/reference/operator/query/eq.md#mongodb-query-op.-eq), [`$ne`](https://www.mongodb.com/docs/manual/reference/operator/query/ne.md#mongodb-query-op.-ne), [`$in`](https://www.mongodb.com/docs/manual/reference/operator/query/in.md#mongodb-query-op.-in), and [`$nin`](https://www.mongodb.com/docs/manual/reference/operator/query/nin.md#mongodb-query-op.-nin) operators.

For example, consider a collection that has the document `{ "a": [ 1 ] }`. The path `a.b` doesn't exist in that document.

- In MongoDB 8.x and earlier, the predicate `{ "a.b": { "$ne": null } }` matches the document.

- Starting in MongoDB 9.0, the same predicate doesn't match the document, and the predicate `{ "a.b": { "$eq": null } }` matches it instead.

If your query uses such a predicate, the same `--query` value selects a different set of documents on MongoDB 9.0 than on earlier versions. An operation that filters on `{ "$ne": null }` returns fewer documents. Review any query that compares a dotted path to `null` before you dump or export data from a MongoDB 9.0 deployment. Confirm that the query still selects the documents you expect.

**Note:**

When you use the `--query` option on a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection), you can only query the field specified as the `metaField`.

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.

**Note:**

When you use the `--queryFile` option on a time series collection, you can only query the field specified as the `metaField`.

*Default*: [`primary`](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary)

Specifies the [read preference](https://www.mongodb.com/docs/manual/core/read-preference.md#std-label-replica-set-read-preference) for `mongodump`. The `--readPreference` option can take:

- A string if specifying only the read preference mode:

  ```sh
  --readPreference=secondary
  ```

- A quote-enclosed document to specify the mode, the optional [read preference tag sets](https://www.mongodb.com/docs/manual/tutorial/configure-replica-set-tag-sets.md#std-label-configure-read-pref-tags), and the optional [maxStalenessSeconds:](https://www.mongodb.com/docs/manual/core/read-preference-staleness.md#std-label-replica-set-read-preference-max-staleness)

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

  If specifying the [maxStalenessSeconds](https://www.mongodb.com/docs/manual/core/read-preference-staleness.md#std-label-replica-set-read-preference-max-staleness), the value must be greater than or equal to 90.

`mongodump` defaults to `primary` read preference.

If the read preference is also included in the `--uri connection string <--uri>`, the command-line `--readPreference` overrides the read preference specified in the URI string.

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.

Specifies the directory where `mongodump` will write [BSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-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.

Writes the output to a specified archive file or, if the archive file is unspecified, writes to the standard output (`stdout`). An archive file is a single-file alternative to multiple BSON files.

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

  ```javascript
  mongodump --archive=<file>
  ```

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

  ```javascript
  mongodump --archive
  ```

You cannot use the `--archive <mongodump --archive>` option with the `--out <mongodump --out>` option.

**Note:**

If [`mongodump`](https://www.mongodb.com/docs/database-tools/mongodump.md#mongodb-binary-bin.mongodump) writes to an archive file, `mongodump` performance can improve. For more information on `mongodump` performance impacts, see [Output Format Considerations.](https://www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools.md#std-label-considerations-output-format)

Captures any [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) entries that occur during the `mongodump` operation so the dump reflects a single moment in time.

Where `mongodump` puts the oplog data depends on the output target:

- For a directory dump, `mongodump` writes the oplog entries to an `oplog.bson` file at the top level of the output directory.

- For an archive dump, the archive includes the oplog entries.

When you restore, replay the oplog entries with [`mongorestore --oplogReplay`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--oplogReplay). You can use `mongodump --oplog` together with `mongorestore --oplogReplay` to ensure the data is current and includes all the writes that occurred during the dump.

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.

To back up individual replica sets while still accepting writes, use `--oplog`.

**Important:**

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

- [`renameCollection`](https://www.mongodb.com/docs/manual/reference/command/renameCollection.md#mongodb-dbcommand-dbcmd.renameCollection)

- [`db.collection.renameCollection()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.renameCollection.md#mongodb-method-db.collection.renameCollection)

- [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) with [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out)

- [`mapReduce`](https://www.mongodb.com/docs/manual/reference/command/mapReduce.md#mongodb-dbcommand-dbcmd.mapReduce) (this operation implicitly renames a collection)

- Operations that create or modify users, roles, or privileges

- [`setDefaultRWConcern`](https://www.mongodb.com/docs/manual/reference/command/setDefaultRWConcern.md#mongodb-dbcommand-dbcmd.setDefaultRWConcern) and other commands that modify cluster-wide settings

`--oplog` has no effect when running `mongodump` on a `mongos` instance to dump the entire contents of a sharded cluster.

`--oplog` only works against nodes that maintain an [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog). This includes all members of a replica set.

`--oplog` does not dump the oplog collection.

You can't run `mongodump` with `--oplog` on a sharded cluster. To back up sharded clusters with `mongodump`, see [Back Up a Self-Managed Sharded Cluster with a Database Dump.](https://www.mongodb.com/docs/manual/tutorial/backup-sharded-cluster-with-database-dumps.md#std-label-backup-sharded-dumps)

**Note:**

To use `mongodump` with `--oplog`, you must create a full dump of a [replica set](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-replica-set) member. `mongodump` with  `--oplog` fails if you use any of the following options to limit the data to be dumped:

- `--db`

- `--collection`

- `--dumpDbUsersAndRoles`

- `--query`

**Warning:**

Don't change the feature compatibility version (FCV) between MongoDB 8.x and MongoDB 9.0 while `mongodump --oplog` runs on a deployment that has time series collections. The resulting dump spans a time series format conversion, which [`mongorestore --oplogReplay`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--oplogReplay) can't replay.

Starting in Database Tools 100.18.0, `mongodump` fails instead of producing a dump that you can't restore. To learn more, see [Oplog Replay Across a Time Series Format Conversion.](https://www.mongodb.com/docs/database-tools/mongorestore/mongorestore-behavior-access-usage.md#std-label-mongorestore-time-series-format-conversion)

For an end-to-end example of using `mongodump --oplog` together with [`mongorestore --oplogReplay`](https://www.mongodb.com/docs/database-tools/mongorestore.md#std-option-mongorestore.--oplogReplay) to create a consistent backup while accepting writes, see [Create and Restore Consistent Backup Files.](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-examples.md#std-label-mongodump-example-consistent-backup)

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.

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

To use the `--excludeCollection` option, you must specify a database. You can specify a database with the [`--db`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--db) option or in the [`--uri`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri) connection string.

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

To use the `--excludeCollectionsWithPrefix` option, you must specify a database. You can specify a database with the [`--db`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--db) option or in the [`--uri`](https://www.mongodb.com/docs/database-tools/mongodump.md#std-option-mongodump.--uri) connection string.

*Default*: 4

Number of collections `mongodump` should export in parallel.

When specified, `mongodump` exports [views](https://www.mongodb.com/docs/manual/core/views.md#std-label-views-landing-page) as collections.

**Note:**

Only views are exported. By default, `mongodump` only exports a view's metadata. To export the documents in a view, use the `--viewsAsCollections` option.

For each view, `mongodump` creates a BSON file containing the documents in the view. If you use `mongorestore` with a BSON file created by `mongodump`, the view is 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.

Specifies the compression algorithm that `mongodump` uses for network communication between the `mongodump` client and the MongoDB server. You can use one or more of these values for the `--compressors` option:

- `snappy`

- `zlib`

- `zstd`

If you specify multiple compression algorithms, `mongodump` uses the first one in the list supported by your MongoDB deployment.

For more information on compressors, see the [Go driver network compression documentation.](https://www.mongodb.com/docs/drivers/go/current/fundamentals/connections/network-compression/)

## Learn More

For more information about `mongodump`, see:

- [mongodump Compatibility and Installation](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-compatibility-and-installation.md#std-label-mongodump-compatibility-and-installation)

- [mongodump Behavior, Access, and Usage](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-behavior.md#std-label-mongodump-behavior)

- [mongodump Examples](https://www.mongodb.com/docs/database-tools/mongodump/mongodump-examples.md#std-label-mongodump-examples)

For a tutorial, see [Back Up a Self-Managed Sharded Cluster with a Database Dump.](https://www.mongodb.com/docs/manual/tutorial/backup-sharded-cluster-with-database-dumps.md#std-label-backup-sharded-dumps)

For more information about TLS/SSL and MongoDB, see [Configure mongod and mongos for TLS/SSL](https://www.mongodb.com/docs/manual/tutorial/configure-ssl/) and [TLS/SSL Configuration for Clients.](https://www.mongodb.com/docs/manual/tutorial/configure-ssl-clients/)
