Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Database Tools

mongoexport Behavior, Access, and Usage

On this page

  • Behavior
  • Required Access
  • Learn More

Warning

Data Import and Export Conflicts With ($) and (.)

Starting in MongoDB 5.0, document field names can be ($) prefixed and can contain a (.). However, mongoimport and mongoexport should not be used with field names that make use of these characters.

MongoDB Extended JSON 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 mechanism is an exception to this general rule.

There are also restrictions on using mongoimport and 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.

If you need to preserve all rich BSON data types when using mongoexport to perform full instance backups, be sure to specify Extended JSON v2.0 (Canonical mode) to the --jsonFormat option to mongoexport, in the following fashion:

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

If --jsonFormat is unspecified, mongoexport outputs data in Extended JSON v2.0 (Relaxed mode) by default.

mongoimport will automatically use the JSON format found in the specified target data file when restoring. For example, it will use Extended JSON v2.0 (Canonical mode) if the target data export file was created by mongoexport with --jsonFormat=canonical specified.

mongoexport automatically creates FIPS-compliant connections to a mongod/mongos that is configured to use FIPS mode.

By default, mongoexport uses read preference primary. To override the default, you can specify the read preference in the --readPreference command line option or in the --uri connection string.

If you specify read preference in the URI string and the --readPreference, the --readPreference value overrides the read preference specified in the URI string.

mongoexport requires read access on the target database.

Ensure that the connecting user possesses, at a minimum, the read role on the target database.

When connecting to a mongod or mongos that enforces Authentication, ensure you use the required security parameters based on the configured authentication mechanism.

← mongoexport Compatibility and Installation