Docs Menu
Docs Home
MongoDB Compass

Import and Export Data

On this page

  • Import Data into a Collection
  • Export Data from a Collection
  • Import and Export Data from the Command Line

You can use MongoDB Compass to import and export data to and from collections. Compass supports import and export for both JSON and CSV files. To import or export data to or from a collection, navigate to the detailed collection view by either selecting the collection from the Databases tab or clicking the collection in the left-side navigation.

MongoDB Compass can import data into a collection from either a JSON or CSV file.

  • Importing data into a collection is not permitted in MongoDB Compass Readonly Edition.

  • Importing data is not available if you are connected to a Data Lake.

Before you can import your data into MongoDB Compass you must first ensure that it is formatted correctly.

To import your formatted data into a collection:


To learn how to connect to a deployment, see Connect to MongoDB.


You can either select the collection from the Collections tab or click the collection in the left-hand pane.


Select either a JSON or CSV file to import and click Select.

If you are importing a CSV file, you may specify fields to import and the types of those fields under Specify Fields and Types.

Select fields to import from a CSV file
click to enlarge

To exclude a field from a CSV file you are importing, uncheck the checkbox next to that field name. To select a type for a field, use the dropdown menu below that field name.


Under Options, configure the import options for your use case.

If you are importing a CSV file, you may select how your data is delimited.

For both JSON and CSV file imports, you can toggle Ignore empty strings and Stop on errors:

  • If checked, Ignore empty strings drops fields with empty string values from your imported documents. The document is still imported with all other fields.

  • If checked, Stop on errors prevents any data from being imported in the event of an error. If unchecked, data is inserted until an error is encountered and successful inserts are not rolled back. The import operation will not continue after encountering an error in either case.


A progress bar displays the status of the import. If an error occurs during import, the progress bar turns red and an error message appears in the dialog. To see all errors, click View Log.

After successful import, the dialog closes and Compass displays the collection page containing the newly imported documents.

MongoDB Compass can export data from a collection as either a JSON or CSV file. If you specify a filter or aggregation pipeline for your collection, Compass only exports documents which match the specified query or pipeline results.

  • Avoid exporting to CSV files when possible. CSV files may lose type information and are not suitable for backing up your data.

  • You can use a query filter to export only the documents that match the filter.

  • You can use the Project field in the query bar to specify the fields to return or export.

To import and export data from the command line, you can use MongoDB's Database Tools. See mongoimport and mongoexport.

← In-Use Encryption Tutorial