Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tenthousandcoffees/mongodb-snapshot

Package Overview
Dependencies
Maintainers
4
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tenthousandcoffees/mongodb-snapshot

Manages MongoDB snapshots, provides functionality to deliver MongoDB content between data sources for backup and restore

  • 1.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
79
increased by21.54%
Maintainers
4
Weekly downloads
 
Created
Source

mongodb-snapshot

Dump and restore MongoDB content between data sources.

Installation

npm install @tenthousandcoffees/mongodb-snapshot

Usage

dump mongodb database to a local file

import { MongoTransferer, MongoDBDuplexConnector, LocalFileSystemDuplexConnector } from '@tenthousandcoffees/mongodb-snapshot';

async function dumpMongo2Localfile() {
    const mongo_connector = new MongoDBDuplexConnector({
        connection: {
            uri: `mongodb://<username>:<password>@<hostname>:<port>`,
            dbname: '<database-name>',
        },
    });

    const localfile_connector = new LocalFileSystemDuplexConnector({
        connection: {
            path: './backup.tar',
        },
    });

    const transferer = new MongoTransferer({
        source: mongo_connector,
        targets: [localfile_connector],
    });

    for await (const { total, write } of transferer) {
        console.log(`remaining bytes to write: ${total - write}`);
    }
}

restore mongodb database from a local file

import { MongoTransferer, MongoDBDuplexConnector, LocalFileSystemDuplexConnector } from '@tenthousandcoffees/mongodb-snapshot';

async function restoreLocalfile2Mongo() {
    const mongo_connector = new MongoDBDuplexConnector({
        connection: {
            uri: `mongodb://<username>:<password>@<hostname>:<port>`,
            dbname: '<database-name>',
        },
    });

    const localfile_connector = new LocalFileSystemDuplexConnector({
        connection: {
            path: './backup.tar',
        },
    });

    const transferer = new MongoTransferer({
        source: localfile_connector,
        targets: [mongo_connector],
    });

    for await (const { total, write } of transferer) {
        console.log(`remaining bytes to write: ${total - write}`);
    }
}

copy mongodb database to another mongodb database

import { MongoTransferer, MongoDBDuplexConnector } from '@tenthousandcoffees/mongodb-snapshot';

async function copyMongo2Mongo() {
    const mongo_connector_1 = new MongoDBDuplexConnector({
        connection: {
            uri: `mongodb://<username>:<password>@<hostname>:<port>`,
            dbname: '<database-name>',
        },
    });

    const mongo_connector_2 = new MongoDBDuplexConnector({
        connection: {
            uri: `mongodb://<username>:<password>@<hostname>:<port>`,
            dbname: '<database-name>',
        },
    });

    const mongo_connector_3 = new MongoDBDuplexConnector({
        connection: {
            uri: `mongodb://<username>:<password>@<hostname>:<port>`,
            dbname: '<database-name>',
        },
    });

    const transferer = new MongoTransferer({
        source: mongo_connector_1,
        targets: [mongo_connector_2, mongo_connector_3],
    });

    for await (const { total, write } of transferer) {
        console.log(`remaining bytes to write: ${total - write}`);
    }
}

FAQs

Package last updated on 23 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc