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

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

# mongoimport Behavior, Access, and Usage

**Warning: Data Import and Export Conflicts With ($) and (.)**

Starting in MongoDB 5.0, document field names can be prefixed with a dollar character (`$`) and can contain a period character (`.`). However, [`mongoimport`](https://www.mongodb.com/docs/database-tools/mongoimport.md#mongodb-binary-bin.mongoimport) and [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) won't work with field names that use those characters.

[MongoDB Extended JSON v2](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json.md#std-label-extended-json-high-level-ref-v2) cannot differentiate between type wrappers and fields that happen to have the same name as type wrappers. Do not use Extended JSON formats in contexts where the corresponding BSON representations might include (`$`) prefixed keys. The [DBRef](https://www.mongodb.com/docs/manual/reference/database-references.md#std-label-dbref-explanation) mechanism is an exception to this general rule.

There are also restrictions on using [`mongoimport`](https://www.mongodb.com/docs/database-tools/mongoimport.md#mongodb-binary-bin.mongoimport) and [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) with (`.`) in field names. Since CSV files use the (`.`) to represent data hierarchies, a (`.`) in a field name will be misinterpreted as a level of nesting.

## Behavior

### Type Fidelity

If you need to preserve all rich [BSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-BSON) data types when using [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) to perform full instance backups, specify [Extended JSON v2.0 (Canonical mode)](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json.md#std-label-mongodb-extended-json-v2) to the [`--jsonFormat`](https://www.mongodb.com/docs/database-tools/mongoexport.md#std-option-mongoexport.--jsonFormat) option:

```javascript
mongoexport --jsonFormat=canonical --collection=<coll> <connection-string>
```

If you don't specify `--jsonFormat`, [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) outputs data in [Extended JSON v2.0 (Relaxed mode)](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json.md#std-label-mongodb-extended-json-v2) by default.

[`mongoimport`](https://www.mongodb.com/docs/database-tools/mongoimport.md#mongodb-binary-bin.mongoimport) automatically uses the [JSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-JSON) format found in the specified target data file when restoring. For example, if the target data export file was created by [`mongoexport`](https://www.mongodb.com/docs/database-tools/mongoexport.md#mongodb-binary-bin.mongoexport) with `--jsonFormat=canonical` specified, it uses Canonical mode).

### JSON Format

[`mongoimport`](https://www.mongodb.com/docs/database-tools/mongoimport.md#mongodb-binary-bin.mongoimport) requires import data to be in either [Extended JSON v2.0 (Canonical)](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/) or [Extended JSON v2.0 (Relaxed)](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/) format by default. For import data formatted using Extended JSON v1.0, specify the [`--legacy`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--legacy) option.

**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`, you should use the corresponding version of `mongoimport`.

### Document Order

By default, `mongoimport` may insert documents in a random order. To preserve document order during the restore process, use [`--maintainInsertionOrder`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--maintainInsertionOrder).

### Encoding

`mongoimport` only supports data files that are UTF-8 encoded. Using other encodings produces errors.

### FIPS

`mongoimport` automatically creates FIPS-compliant connections to a [`mongod`/](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod)[`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) that is [configured to use FIPS mode.](https://www.mongodb.com/docs/manual/tutorial/configure-fips/)

### Write Concern

If you specify write concern in both the [`--writeConcern`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--writeConcern) option and the [`--uri connection string`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--uri) option, the [`--writeConcern`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--writeConcern) value overrides the write concern specified in the URI string.

### Batches

`mongoimport` uses a maximum batch size of 100,000 to perform bulk insert/upsert operations.

### Time Series Collections

To import time series data, you must create a [time series collection](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-landing) before running `mongoimport`. `mongoimport` does not support creating time series collections automatically. For more information about creating a collection, see [`createCollection()`.](https://www.mongodb.com/docs/manual/reference/method/db.createCollection.md#mongodb-method-db.createCollection)

### Crash Behavior

If `mongoimport` crashes, it can leave the system in an inconsistent state where only *some* of the data was imported, but not all of it. After a crash, delete any imported data and rerun the process from the beginning.

## Required Access

In order to connect to a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) that enforces authorization with the [`--auth`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--auth) option, you must use the [`--username`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--username) and [`--password`](https://www.mongodb.com/docs/database-tools/mongoimport.md#std-option-mongoimport.--password) options. The connecting user must possess, at a minimum, the [`readWrite`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-readWrite) role on the database into which they are importing data.

## Learn More

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

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

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