Backing Up and Restoring MongoDB

By Ercan S. - 17/04/2025 - 0 comments

This guide outlines the steps to back up and restore MongoDB databases using the official MongoDB Database Tools.

1. Download MongoDB Database Tools

Obtain the MongoDB Database Tools from the official website:

https://www.mongodb.com/try/download/database-tools

2. Backing Up a Database

Use the `mongodump` utility to create a backup of your database:

.\mongodump.exe --db=<<db_name>> --out <<dump_path>>

Replace `<<db_name>>` with the name of your database and `<<dump_path>>` with the desired output directory.

3. Restoring a Backup

- Local Deployment:

To restore the backup to a local MongoDB instance:

.\mongorestore.exe --uri "mongodb://localhost:27017/<<db_name>>" <<dump_path>>

- Remote Deployment (e.g., MongoDB Atlas):

To restore the backup to a remote MongoDB instance:

.\mongorestore.exe --uri "mongodb+srv://username:password@host/<<db_name>>?replicaSet=atlas-ica9cq-shard-0&authSource=admin" <<dump_path>>

Ensure you replace `username`, `password`, `host`, and other placeholders with your actual connection details.
 

Tags: mongodb, dump, restore