MongoDB – How to export and import data

Exporting a database

mongoexport -d my_database -o ./dump

This exports a database with all its collections and documents to a dump folder. All collections will be dumped in an equally named folder in the ./dump folder.

Importing a database

mongorestore -d my_database ./dump/my_database 

This imports a previously exported database with all its collections and documents.