Mongo Export/Import as JSON file in Linux/Mac

Fima Sultana
Jan 26, 2023

First install Mongodb tools in MAC:

brew install mongodb/brew/mongodb-database-tools

in ubuntu:

sudo apt install ./mongodb-database-tools-*-100.5.1.deb

For importing a Mongodb use the following command:

mongoimport --uri mongodb+srv://$username:$password@$connection_string/$destination_db_name --collection $collection_name --file /Users/$user/Desktop/db-backup/$collection_name.json

For exporting a Mongodb use the following command:

mongoexport --uri mongodb+srv://$username:$password@$connection_string/$source_db_name --collection $collection_name --type json --out /Users/$user/Desktop/db-backup/$collection_name.json

Hope this helps :)

--

--

Fima Sultana
Fima Sultana

Written by Fima Sultana

DevOps Engineer at angkas.com | Former Senior Site Reliability Engineer at 10minuteschool.com

No responses yet