Home > Articles > Web Development

  • Print
  • + Share This
Like this article? We recommend

Importing and Exporting Data

By default, exporting data from MongoDB produces a JSON document. Use the mongoexport command:

mongoexport --db sales --collection contacts --query '{"level": 3}'

This command exports the contacts collection of the sales database, but only documents within the collection having a field named level with a value of 3. Use the –csv option to export as a .csv file.

To import data, the process is similar and so is the command. Use the mongoimport command:

mongoimport --collection contacts --file contacts.json

This command imports contact data from the contacts.json file into the current database’s contacts collection. To import a .csv file, use the –type option (as in –type csv).

  • + Share This
  • 🔖 Save To Your Account