A simple and efficient npm package for duplicating data between MongoDB databases, even within the same URI.
To install the package, use npm:
npm install duplicate-mongo-db
Or with yarn:
yarn add duplicate-mongo-db
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);
});
-
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.
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);
});
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);
});
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the ISC License - see the LICENSE file for details.