Stanislas Randriamilasoa
2 min readNov 19, 2022

--

How to export remote mongodb database with mongodump on MacOS

Source : https://www.mongodb.com/

In this article we will see how to export remote mongodb database from command line on Mac.

MongoDB is a cross-platform database that can be used in any operating system. It is written in C++ and has a document-oriented data model. Its storage engine supports dynamic schema, indexing, and real-time queries.

MongoDB databases are stored on the filesystem of the server machine. One way to back up these databases is by using mongodump — a command line utility for backing up MongoDB databases to files on disk.

1- Install mongodump

mongodump comes with Mongo database installation, so to get it, you can use the following command:

$brew tap mongodb/brew; brew install mongodb-community

It’s highly recommended to install brew on your mac, and you can do it by using the following command from Homebrew website.

$/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then you can simply execute this command to export your database:

$mongodump --host MONGODB_HOST -d MONGODB_DB_NAME --port MONGODB_PORT --authenticationDatabase=admin --username MONGODB_USERNAME --password MONGODB_PASSWORD --out /path/to/your/local/export

Note that the — authenticationDatabase=admin can be optionnal

Example:

$mongodump --host db.example.com -d my database --port 27017 --authenticationDatabase=admin --username root --password dbpassword --out /Users/user/Documents/exportdb

All the database collections should be exported under the target — out folder.
That’s all; I hope this may help you ;)

--

--