> 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

# `mongoimport`

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.

This documentation is for version `100.20.1` of `mongoimport`.

## Synopsis

`mongoimport` imports content from an [Extended JSON](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/), CSV, or TSV export created by [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport), or potentially, another third-party export tool.

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

[`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) provides data export capabilities.

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/)

**Tip:**

You can also import and export data using the graphical user interface tool MongoDB Compass. For details, see [MongoDB Compass Import and Export.](https://www.mongodb.com/docs/compass/current/import-export.md#std-label-compass-import-export)

## Security Considerations

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

## Syntax

`mongoimport` syntax:

```sh
mongoimport <options> <connection-string> <file>
```

## Options

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

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`.)

Runs `mongoimport` 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 events

- connection closed events

Returns the `mongoimport` release number.

**New in version 100.3.0**

Specifies the full path to a YAML configuration file that contains sensitive values for the following `mongoimport` 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 `mongoimport`, 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 `mongoimport` 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) `mongoimport` 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]]"
```

**Note:**

If you don't specify a database with the [`--db`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--db) or [`--uri`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--uri) option, `mongoimport` uses the `test` database by default. If the `test` database doesn't exist, `mongoimport` creates the database.

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

```none
mongoimport 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
mongoimport --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/mongoimport.md#std-option-mongoimport.--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 `mongoimport` 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, `mongoimport` 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, `mongoimport` 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 (e.g. `[<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 connection 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) 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.

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/)

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.

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/)

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`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--ssl) option to connect 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) 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.

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/)

Specifies the password to de-crypt the certificate-key file (i.e. [`--sslPEMKeyFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--sslPEMKeyFile)). Use the [`--sslPEMKeyPassword`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--sslPEMKeyPassword) option only if the certificate-key file is encrypted. In all cases, the `mongoimport` redacts 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`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--sslPEMKeyPassword) option, the `mongoimport` prompts 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.

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/)

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

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/)

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 a warning for invalid certificates.

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

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/)

Disables the validation of the hostnames in TLS/SSL certificates. Allows `mongoimport` 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.

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/)

Specifies a username with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the [`--password`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--password) and [`--authenticationDatabase`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--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/mongoimport.md#std-option-mongoimport.--authenticationMechanism), you can specify your AWS access key ID in:

- this field,

- the [`connection string`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--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/mongoimport/mongoimport-examples.md#std-label-mongoimport-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`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--username) and [`--authenticationDatabase`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--authenticationDatabase) options.

To prompt the user for the password, pass the [`--username`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--username) option without [`--password`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--password) or specify an empty string as the [`--password`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--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/mongoimport.md#std-option-mongoimport.--authenticationMechanism), you can specify your AWS secret access key in:

- this field,

- the [`connection string`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--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/mongoimport/mongoimport-examples.md#std-label-mongoimport-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/mongoimport.md#std-option-mongoimport.--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/mongoimport.md#std-option-mongoimport.--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/mongoimport/mongoimport-examples.md#std-label-mongoimport-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/mongoimport.md#std-option-mongoimport.--authenticationMechanism)

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

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 `mongoimport` instance uses to authenticate to the [`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)

**Changed in version 100.1.0**

Starting in version `100.1.0`, `mongoimport` 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.

Specify the hostname of a service using [GSSAPI/Kerberos](https://www.mongodb.com/docs/manual/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 the name of the database on which to run the `mongoimport`.

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.

**Note:**

If you don't specify a database with the [`--db`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--db) or [`--uri`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--uri) option, `mongoimport` uses the `test` database by default. If the `test` database doesn't exist, `mongoimport` creates the database.

Specifies the collection to import. If you do not specify [`--collection`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--collection), `mongoimport` reads the collection name from the input filename, omitting the file's extension if it has one.

Specify a comma separated list of field names when importing [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) files that do not have field names in the first (i.e. header) line of the file.

To also specify the field type as well as the field name, use [`--fields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fields) with [`--columnsHaveTypes`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes)

If you attempt to include [`--fields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fields) when importing JSON data, `mongoimport` returns an error. [`--fields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fields) is only for [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) imports.

As an alternative to [`--fields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fields), the [`--fieldFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fieldFile) option allows you to specify a file that holds a list of field names if your [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) file does not include field names in the first line of the file (i.e. header). Place one field per line.

To also specify the field type as well as the field name, use [`--fieldFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fieldFile) with [`--columnsHaveTypes`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes)

If you attempt to include [`--fieldFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fieldFile) when importing JSON data, `mongoimport` returns an error. [`--fieldFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fieldFile) is only for [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) imports.

Ignores empty fields in [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) and [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) exports. If not specified, `mongoimport` creates fields without values in imported documents.

If you attempt to include [`--ignoreBlanks`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--ignoreBlanks) when importing JSON data, `mongoimport` returns an error. [`--ignoreBlanks`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--ignoreBlanks) is only for [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) imports.

Specifies the file type to import. The default format is [JSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-JSON), but it's possible to import [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) and [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) files.

The `csv` parser accepts that data that complies with [RFC-4180](https://tools.ietf.org/html/4180). As a result, backslashes are *not* a valid escape character. If you use double-quotes to enclose fields in the CSV data, you must escape internal double-quote marks by prepending another double-quote.

Specifies the location and name of a file containing the data to import. If you do not specify a file, `mongoimport` reads data from standard input (e.g. "stdin").

Modifies the import process so that the target instance drops the collection and any associated [indexes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-index) before importing data from the input.

If using [`--type csv`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--type) or [`--type tsv`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--type), uses the first line as field names. Otherwise, `mongoimport` imports the first line as a distinct document.

If you attempt to include [`--headerline`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--headerline) when importing JSON data, `mongoimport` returns an error. [`--headerline`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--headerline) is only for [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) imports.

**New in version 100.0.0**

Interpret natural numbers in fields as array indexes when importing [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) files.

Field names must be in the form `<colName>.<arrayIndex>` where `arrayIndex` is a natural number beginning with `0` and increasing sequentially by `1` for each member of the array.

For example, with the following [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) file:

```javascript
a.0,a.1,a.2,a.3
red,yellow,green,blue
```

An import with the [`--useArrayIndexFields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--useArrayIndexFields) option would result in the following document:

```javascript
"a" : [ "red", "yellow", "green", "blue" ]
```

If using the [`--columnsHaveTypes`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes) option as well, use the form `<colName>.<arrayIndex>.<type>(<arg>)` to specify both the array index and type for each field. See [`--columnsHaveTypes`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes) for more information.

Numerical keys with leading zeros (e.g. `a.000,a.001`) are not interpreted as array indexes.

If the first part of a key is a natural number (e.g. `0.a,1.a`), it is interpreted as a document key, and not an array index.

If using the [`--ignoreBlanks`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--ignoreBlanks) option with [`--useArrayIndexFields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--useArrayIndexFields), `mongoimport` returns an error if you attempt to import a document that contains a blank value (e.g. `""`) for an array index field.

The [`--useArrayIndexFields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--useArrayIndexFields) option has no effect when importing [JSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-JSON) data, as arrays are already encoded in [JSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-JSON) format.

*Default*: insert

Specifies how the import process should handle existing documents in the database that match documents in the import file.

By default, `mongoimport` uses the `_id` field to match documents in the collection with documents in the import file. To specify the fields against which to match existing documents for the `upsert`, `merge`, and `delete` modes, use [`--upsertFields`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--upsertFields)

| Value | Description |
| --- | --- |
| `insert` | Insert the documents in the import file. `mongoimport` returns an error if you attempt to import a document that contains a duplicate value for a field with a [unique index](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique), such as `_id`. |
| `upsert` | Replace existing documents in the database with matching documents from the import file. `mongoimport` inserts all other documents. [Replace Matching Documents during Import](https://www.mongodb.com/docs/database-tools/mongoimport/mongoimport-examples.md#std-label-ex-mongoimport-upsert) describes how to use [`--mode`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--mode) `upsert`. |
| `merge` | Merge existing documents that match a document in the import file with the new document. `mongoimport` inserts all other documents. [Merge Matching Documents during Import](https://www.mongodb.com/docs/database-tools/mongoimport/mongoimport-examples.md#std-label-ex-mongoimport-merge) describes how to use [`--mode`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--mode) `merge`. |
| `delete` | Delete existing documents in the database that match a document in the import file. `mongoimport` takes *no action* on non-matching documents. [Delete Matching Documents](https://www.mongodb.com/docs/database-tools/mongoimport/mongoimport-examples.md#std-label-ex-mongoimport-delete) describes how to use [`--mode`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--mode) `delete`. **New in version 100.0.0** |

Specifies a list of fields for the query portion of the import process. [`--upsertFields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--upsertFields) can be used with [`--mode`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--mode) `upsert`, `merge`, and `delete`.

Use this option if the `_id` fields in the existing documents don't match the field in the document, but another field or field combination can uniquely identify documents as a basis for performing upsert operations.

If you do not specify a field, [`--upsertFields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--upsertFields) upserts on the basis of the `_id` field.

To ensure adequate performance, indexes should exist for the field or fields you specify with [`--upsertFields`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--upsertFields)

Forces `mongoimport` to halt the insert operation at the first error rather than continuing the operation despite errors.

By default, `mongoimport` continues an operation when it encounters duplicate key and document validation errors. To ensure that the program stops on these errors, specify [`--stopOnError`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--stopOnError)

Accepts the import of data expressed with multiple MongoDB documents within a single [JSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-JSON) array. Limited to imports of 16 MB or smaller.

Use [`--jsonArray`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--jsonArray) in conjunction with [`mongoexport --jsonArray`.](https://www.mongodb.com/docs/database-tools/mongoexport.md#std-option-mongoexport.--jsonArray)

Indicates that the import data is in [Extended JSON v1 format](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json-v1/) instead of the default [Extended JSON v2 format.](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/)

**Tip:**

In general, the versions of [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) and `mongoimport` should match. That is, to import data created from [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport), you should use the corresponding version of `mongoimport`.

For example, if the import data is in v1 format:

```javascript
{"_id":1.0,"myregfield":{"$regex":"foo","$options":"i"}}
```

Import without the [`--legacy`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--legacy) option results in the following document in the collection:

```javascript
{ "_id" : 1, "myregfield" : { "$regex" : "foo", "$options" : "i" } }
```

Import with the [`--legacy`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--legacy) results in the following document in the collection:

```javascript
{ "_id" : 1, "myregfield" : { "$regularExpression" : { "pattern" : "foo", "options" : "i" } } }
```

*Default*: false

If specified, `mongoimport` inserts the documents in the order of their appearance in the input source. That is, both the bulk write batch order and document order within the batches are maintained.

Specifying [`--maintainInsertionOrder`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--maintainInsertionOrder) also enables [`--stopOnError`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--stopOnError) and sets [`numInsertionWorkers`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--numInsertionWorkers) to 1.

If unspecified, `mongoimport` may perform the insertions in an arbitrary order.

*Default*: 1

Specifies the number of insertion workers to run concurrently.

For large imports, increasing the number of insertion workers may increase the speed of the import.

*Default*: majority

Specifies the [write concern](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-write-concern) for each write operation that `mongoimport` performs.

Specify the write concern as a document with [w options:](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-wc-w)

```sh
--writeConcern "{w:'majority'}"
```

If the write concern is also included in the [`--uri connection string`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--uri), the command-line [`--writeConcern`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--writeConcern) overrides the write concern specified in the URI string.

Enables `mongoimport` to bypass [document validation](https://www.mongodb.com/docs/manual/core/schema-validation/) during the operation. This lets you insert documents that do not meet the validation requirements.

Instructs `mongoimport` that the field list specified in [`--fields`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fields), [`--fieldFile`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--fieldFile), or [`--headerline`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--headerline) specifies the types of each field.

Field names must be in the form of `<colName>.<type>(<arg>)`. You must backslash-escape the following characters if you wish to include them in an argument: `(`, `)`, and `\`.

| `type` | Supported Arguments | Example Header Field |
| --- | --- | --- |
| `auto()` | None. | `misc.auto()` |
| `binary(<arg>)` | `base32` ([RFC4648](https://tools.ietf.org/html/rfc4648) encoding schema); `base64` ([RFC4648](https://tools.ietf.org/html/rfc4648) encoding schema); `hex` | `user thumbnail.binary(base64)` |
| `boolean()` | None. | `verified.boolean()` |
| `date(<arg>)` | Alias for `date_go(<arg>)`. [Go Language time.Parse format.](https://golang.org/src/time/format.go) | `created.date(2006-01-02 15:04:05)` |
| `date_go(<arg>)` | [Go Language time.Parse format](https://golang.org/src/time/format.go) | `created.date_go(2006-01-02T15:04:05Z)` |
| `date_ms(<arg>)` | [Microsoft SQL Server FORMAT format](https://msdn.microsoft.com/en-us/library/hh213505.aspx) | `created.date_ms(yyyy-MM-dd H:mm:ss)` |
| `date_oracle(<arg>)` | [Oracle Database TO_DATE format](https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm). | `created.date_oracle(YYYY-MM-DD HH24:MI:SS)` |
| `decimal()` | None | `price.decimal()` |
| `double()` | None. | `revenue.double()` |
| `int32()` | None. | `followerCount.int32()` |
| `int64()` | None. | `bigNumber.int64()` |
| `string()` | None. | `zipcode.string()` |

See [Import CSV with Specified Field Types](https://www.mongodb.com/docs/database-tools/mongoimport/mongoimport-examples.md#std-label-example-csv-import-types) for sample usage.

If you attempt to include [`--columnsHaveTypes`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes) when importing JSON data, `mongoimport` returns an error. [`--columnsHaveTypes`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes) is only for [CSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-CSV) or [TSV](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-TSV) imports.

*Default*: stop

Specifies how `mongoimport` handles type coercion failures when importing CSV or TSV files with [`--columnsHaveTypes`.](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--columnsHaveTypes)

[`--parseGrace`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--parseGrace) has no effect when importing JSON documents.

| Value | Description |
| --- | --- |
| `autoCast` | Assigns a type based on the value of the field. For example, if a field is defined as a `double` and the value for that field was `"foo"`, `mongoimport` would make that field value a string type. |
| `skipField` | For the row being imported, `mongoimport` does not include the field whose type does not match the expected type. |
| `skipRow` | `mongoimport` does not import rows containing a value whose type does not match the expected type. |
| `stop` | `mongoimport` returns an error that ends the import. |

## Learn More

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

- [mongoimport Behavior](https://www.mongodb.com/docs/database-tools/mongoimport/mongoimport-behavior.md#std-label-mongoimport-behavior-access-usage)

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

- [MongoDB Compass Import and Export](https://www.mongodb.com/docs/compass/current/import-export.md#std-label-compass-import-export)
