Mongo Export/Import as JSON file in Linux/Mac
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 :)