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

update-mongo

v0.0.4

Published

An easy way to run MongoDB update stripts in Node.

Downloads

16

Readme

update-mongo

A simple Node.js Module to run updates for MongoDB.

About

All commands in the Mongo shell are synchronous and therefore simple to control the flow of execution, but that is not the case with the Native Node.js Driver. Using the update-mongo interface, you can easily write scripts for the mongo shell and run them during code execution.

update-mongo allows you to run update scripts for MongoDB without interacting with the Mongo DB Native NodeJS Driver. This is an open source project under the MIT license, see LICENSE.md for additional information.

Skip to Examples on how to use update-mongo

Installation

npm install --save update-mongo

Usage

One method is provided: updates.run(scripts, callback);

See Scripts for more information on how the scripts are loaded. The callback function takes two parameters:

var callback = function(error, info) {};

Basic usage is as follows:

var updates = require('update-mongo')(options);

// Run the given update scripts in order, then execute the given callback function.
updates.run(scripts, callback);

Options

The options are given as an object upon loading update-mongo. The only required option is, db, which defines the database the updates will be run against.

var updates = require('update-mongo')(options);
var options = {
  db: '',     // String [required] - The database to connect to and perform updates.
  prefix: '', // String - The string to affix before each given update file.
  suffix: ''  // String - The string to affix after each given update file.
};

Scripts

The scripts provided to updates.run() can be provided in a few different ways: and array of strings (script file names) to run in-order, a combination of JavaScript functions and strings, or an array of the previous.

Note: When functions are supplied, the require a single parameter, a callback function, which will be called when the function is complete.

Possible combinations follow:

// The order of execution in this example is: script1, script2, script3
updates.run([
  './script1',
  './script2',
  './script3'
], callback);

// The order of execution in this example is: function A, script2, function B
updates.run([
  function A(done) { done(); },
  'script2',
  function B(done) { done(); }
], callback);

// The order of execution in this example is: script1, function A, script2,
// function B, script3
updates.run([
  './script1',
  [
    function A(done) { done(); },
    './script2',
    function B(done) { done(); }
  ],
  './script3'
], callback);

If a String is given in the scripts array, update-mongo will look for the file given by:

options.prefix + script + options.suffix

Example

// The Script to run:  ./scripts/script1.js

var updates = require('update-mongo')({
  db: 'foo',
  prefix: './scripts/',
  suffix: '.js'
});

updates.run([
  'script1'
], callback);

Example

var updates = require('update-mongo')({
  db: 'some-test-db'
});

// Run the given update scripts in order, then execute the given callback function.
updates.run([
  './script1',
  './script2',
  './script3'
], function() {
  // Do something when all updates are complete.
  console.log('Done running update scripts1-3');
});