npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dbclone

v0.0.4

Published

Utility to move data between NoSQL databases.

Downloads

9

Readme

dbclone

NPM Version NPM Downloads MIT License Build status Code coverage

Utility to move data between NoSQL databases.

The major difference between this and mongodump is that I like this syntax more.

dbclone also makes storing multiple backups and restoring them easier. It's also more controlled as you can change the target database names during these operations, whitelist or blacklist collections you'd like to use.

It also includes a few extra utils like dropping databases and counting collection sizes.

Currently it only supports MongoDB but other backends are also planned.

Usage in terminal

You can use dbclone command in your terminal if you install the package globally (npm install dbclone -g).

CLI OPTIONS

Supported modes: import, export, count, drop.

They need MongoDB host (--host) and database name (--db).

You can also specify additional options (--datadir, --exclude)

Count mode expects --collections specified.

Drop mode prompts for confirmation by default - you can override this with --force.

EXAMPLES Cloning database from a remote host into a local DB with a date in its name

dbclone export --host mongo.myapp.com --db=myapp-data --datadir data/20180622-myapp-data --exclude files
dbclone drop --host localhost --db=myapp-data --force
dbclone import --host localhost --db=myapp-data --datadir data/20180622-myapp-data
dbclone count --host localhost --db=myapp-data --collections pages,files

MongoDB URI - Authentication, replica sets

You can provide a fully qualified Mongo URI as host option.

In order to authenticate with username and password you can use the following syntax:

dbclone export --host mongodb://username:[email protected]:11111/my-database --db my-database

Usage in Node.js apps

const dbclone = require('dbclone');

const exportOpts = {
  host: 'mongodb://username:[email protected]:11111',
  db: 'example-data-prod',
  dataDir: 'data/20180622-example-app-data',
  exclude: ['files', 'sessions']
};

const importOpts = {
  host: 'localhost',
  db: '20180622-example-data-prod',
  dataDir: 'data/20180622-example-app-data',
  exclude: ['config']
};

const countOpts = {
  host: 'localhost',
  db: '20180622-example-app-data',
  collections: ['users', 'prod']
};

dbclone.export(exportOpts, (exportErr, exportData) => {
  dbclone.import(importOpts, (importErr, importData) => {
    dbclone.count(countOpts, (countErr, countData) => {
      dbclone.drop(dropOpts, (dropErr, dropData) => {
        console.log('Test completed!');
      });
    });
  });
});

TODO

  • support diffing of two databases/data dirs (enumerate collections, compare document counts)
  • support for indexed properties (opt-out through --noIndex flag)
  • add backends for other database types (DynamoDB to begin with)
  • support multiple conflict resolution strategies (overwrite/merge/replace - write new data on top of existing/only copy missing records/drop original contents first)
  • add clone mode which grabs data from source database and copies it to another
  • add rename mode which will do a clone on the same server and drop the original database
  • clean and consistent interfaces in libs
  • documentation and full JSDoc comments coverage
  • prepare testing strategy
  • implement tests as necessary

Release notes

v0.0.4

  • Maintenance: split up CLI logic into individual pieces
  • Bugfix: passing values correctly through callbacks
  • Feature: friendlier interactive prompt mode
  • Feature: --verbose flag
  • Feature: consistent output in CLI

v0.0.3

  • Maintenance: cleaned up file structure
  • Feature: added drop method (thanks @Dikaeinstein)
  • Feature: added version method

v0.0.2

  • Maintenance: changed license from deprecated LGPL-3.0 to MIT
  • Bugfix: preserving correct types (fixes problem with ObjectIDs imported as strings)
  • Bugfix: fixed include/exclude parsing
  • Feature: added count method (thanks @thiagormagalhaes)

v0.0.1

  • basic import and export functionality