duplicate-mongo-db

1.0.1 • Public • Published

duplicate-mongo-db

npm version License: ISC

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 as targetURI.
  • targetURI: The connection string for the target MongoDB server. Can be the same as sourceURI.
  • 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.

Package Sidebar

Install

npm i duplicate-mongo-db

Weekly Downloads

3

Version

1.0.1

License

ISC

Unpacked Size

6.84 kB

Total Files

4

Last publish

Collaborators

  • alishan22