mongo-utils provides a friendly interface to MongoDB's mongodump and mongorestore commands, as well as some utility functions.
utils.parseConnectionString(connectionString); // mongo connection options object
utils.makeRestoreCommand(connectionString, sourceDir); // mongorestore ...
utils.makeDumpCommand(connectionString, targetDir); // mongodump ...
These functions simply wrap child_process.exec
in a convenient interface. There is absolutely no validation happening. Thus, the absence of an error (as err
argument) does not mean the dump or restore succeeded.
I advise to inspect stdout
and stderr
yourself if you use this module for any important dumps or restores, or verify the results otherwise.
utils.dumpDatabase(connectionString, dirName, function(err, stdout, stderr) {});
utils.dumpHerokuMongoHQDatabase(appName, dirName, function(err, stdout, stderr) {});
utils.restoreDatabase(connectionString, dirName, function(err, stdout, stderr) {});
utils.dumpHerokuMongoHQDatabase(appName, dirName, function(err, stdout, stderr) {});
mongo-utils logs some messages to allow you to see what's going on behind the scenes, primarily when doing the using the dump or restore commands. To see what's being logged, you may assign a log function which takes a single message
argument to utils.log
. By default, utils.log
is a noop.
const utils = require('mongo-utils');
utils.log = (msg) => console.log(msg);
For the commands to work, you need to have mongorestore
and mongodump
in your path.
v2.0.0
Remove Heroku supportv1.1.0
Replace CoffeeScript with plain JSv1.0.0
Orininal version by Meryn Stol
mongo-utils is released under the MIT License.
Copyright (c) 2013 Meryn Stol