duplicate-mongo-db
v1.0.1
Published
A package for MongoDB duplication
Downloads
27
Maintainers
Readme
duplicate-mongo-db
A simple and efficient npm package for duplicating data between MongoDB databases, even within the same URI.
Table of Contents
Installation
To install the package, use npm:
npm install duplicate-mongo-db
Or with yarn:
yarn add duplicate-mongo-db
Usage
Here's how you can use this package in your project:
const duplicateMongoDB = require('duplicate-mongo-db');
const options = {
sourceURI: 'mongodb://sourceURI',
targetURI: 'mongodb://targetURI',
sourceDBName: 'sourceDatabase',
targetDBName: 'targetDatabase',
};
duplicateMongoDB(options)
.then(() => {
console.log('Duplication successful!');
})
.catch((error) => {
console.error('Duplication failed:', error);
});
Options
sourceURI
: The connection string for the source MongoDB server. Can be the same astargetURI
.targetURI
: The connection string for the target MongoDB server. Can be the same assourceURI
.sourceDBName
: The name of the source MongoDB database to be duplicated.targetDBName
: The name of the target MongoDB database where the data will be duplicated.
Examples
Duplicate Databases (Same URI)
const options = {
sourceURI: 'mongodb://localhost:27017',
targetURI: 'mongodb://localhost:27017',
sourceDBName: 'sourceDatabase',
targetDBName: 'targetDatabase',
};
duplicateMongoDB(options)
.then(() => {
console.log('Database duplicated successfully!');
})
.catch((error) => {
console.error('Duplication failed:', error);
});
Duplicate Databases (Different URIs)
const options = {
sourceURI: 'mongodb://sourceURI',
targetURI: 'mongodb://targetURI',
sourceDBName: 'sourceDatabase',
targetDBName: 'targetDatabase',
};
duplicateMongoDB(options)
.then(() => {
console.log('Database duplicated successfully!');
})
.catch((error) => {
console.error('Duplication failed:', error);
});
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the ISC License - see the LICENSE file for details.