A simple Node.js Module to run updates for MongoDB.
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
npm install --save update-mongo
One method is provided:
See Scripts for more information on how the scripts are loaded. The callback function takes two parameters:
Basic usage is as follows:
var updates = options;// Run the given update scripts in order, then execute the given callback function.updates;
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 = 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.;
The scripts provided to
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, script3updates;// The order of execution in this example is: function A, script2, function Bupdates;// The order of execution in this example is: script1, function A, script2,// function B, script3updates;
If a String is given in the scripts array,
update-mongo will look for the file given by:
options.prefix + script + options.suffix
// The Script to run: ./scripts/script1.jsvar updates =db: 'foo'prefix: './scripts/'suffix: '.js';updates;
var updates =db: 'some-test-db';// Run the given update scripts in order, then execute the given callback function.updates;