MongoDB is a popular NoSQL database system that stores and manages data in a flexible and scalable manner. Unlike traditional relational databases, MongoDB uses a document-oriented model, where data is stored in JSON-like documents. This makes it easy to work with dynamic and unstructured data.

MongoDB is known for its ability to handle large volumes of data and scale horizontally, making it suitable for a wide range of applications, from small startups to large enterprises. It provides high performance, automatic sharding for distributing data across multiple servers, and robust support for complex queries.

In essence, MongoDB is a versatile and developer-friendly database system that empowers businesses to efficiently manage their data in a way that suits their evolving needs.

The exercise here is to move the database from one Mongo server to another. One use case for this is to copy a collection, or part of a collection, from a production environment into a development environment.

Migrate database in mongoDB

Migrating a collection from one MongoDB server to another involves transferring data from the source server to the destination server while ensuring data integrity and minimal downtime. This process is crucial for various reasons, such as server upgrades, data consolidation, or changing hosting providers. It typically requires careful planning, data export/import, and possibly synchronization to avoid data loss and maintain application continuity.

So, the process we are going to do is to backup the database from one system and then restore it to another mongo server.

1. Backup Database

Use the following command to backup your Database

mongodump --uri="mongodb://localhost:27017/your_db_name"

2. Restore the backup to the new server

Use the following command to restore the backup to the new DB.

mongorestore --db your_db_name path/to/you/dump/folder/

Please note before restoration you need to create the DB on the new server. The above-mentioned command can use both on Linux & WIndows systems.

Share.

Leave A Reply