A robust tool for seamless migration of data between MongoDB databases, allowing for efficient synchronization, with support for listening to live changes in the source database.
- 📔 Description
⚠️ Before running- ✍️ Syntax
- 🔨 Usage
- 📑 Options
- 🧐 Examples
- 📃 License
- ❤️ Contribution
mongograte
is a command-line tool designed to facilitate the migration of MongoDB collections and databases from a source server to a target server. It supports options for clearing existing data, limiting the number of documents to migrate, and listening to changes for real-time synchronization.
Download and place the script in the desired path. For Linux, to make the script executable, you should assign the appropriate permissions:
sudo chmod +x ./mongograte
For convenience, you may want to move the script to /usr/local/bin
or add its directory to your system's $PATH
variable to run it from anywhere.
The general syntax for using mongograte
is:
mongograte [OPTIONS]
Basic usage example:
mongograte -d myDatabases -s mongodb://host:port -t mongodb://host:port
You can see default values in options section
The following command-line options are supported:
Option | Description | Type | Required | Default value |
---|---|---|---|---|
-d , --databases |
List of target databases to migrate | array | Yes | - |
-s , --source |
Source MongoDB server URI | string | Yes | - |
-t , --target |
Target MongoDB server URI | string | Yes | - |
--collections |
Collections to be migrated from source database | string | No | - |
--drop |
Drop target collections in the target database before migration | boolean | No | false |
--drop-all |
Drop all collections in the target database before migration | boolean | No | false |
--truncate |
Truncate target collections in the target database before migration | boolean | No | true |
-l , --limit |
Maximum number of records to migrate per collection | number | No | 1000 |
--query-limit |
Maximum number of records per query | number | No | 1000 |
--timeout |
Timeout for MongoDB connection (ms) | number | No | 5000 |
--listen |
Enable real-time synchronization of source database changes | boolean | No | false |
-i , --insecure |
Allow using a remote database as the target | boolean | No | false |
--skip-update |
Skip checking for updates | boolean | No | false |
-v , --version |
Show version number | boolean | No | - |
-h , --help |
Display help information | boolean | No | - |
Migrating a Database with Specific Options
To migrate the testDB from a local server to a remote server with the collection drop option enabled and a limit of 500 records, use:
mongograte -d testDB -s mongodb://localhost:port -t mongodb://remotehost:port --drop -l 500
Real-Time Synchronization
To listen for changes in the source database and apply them to the target, use the --listen flag:
mongograte -d myDatabase -s mongodb://host:port -t mongodb://host:port --listen
This will keep your target database in sync with the source in near real-time.
Distributed under the MIT License. See LICENSE
for more information.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a pull request
⭐ Feel free to contribute ⭐