A collection of utilities to make and restore backups via mongodump and mongorestore. mongodump and mongorestore must be installed on your system to use this.
const mongoutils = require('@seiren/mongoutils');
Return the object required for creating dump/restore commands. General mongodb url format accepted (eg: mongodb://localhost:27017/mydatabase
).
const url = "mongodb://localhost/test";
let info = mongoutils.parseMongoUrl(url);
Generate the mongodump command.
let command = mongoutils.createDumpCommand(info, './dump');
Generate the mongorestore command.
let command = mongoutils.createRestoreCommand(info, './dump/test');
Execute a generated command.
mongoutils.executeCommand(command, function(out) { console.log("OUT", out); }, function(err) { console.log("ERROR", err); })
.then(function(result) {
console.log(result);
})
.catch(function(error) {
throw error;
})
The out
and err
functions are optional. If you wish to use err
but not out
, set out
to null.
Returns true if mongodump/mongorestore if installed on the system. Returns false if not.
mongoutils.checkInstalled()
.then(function(result) {
console.log(result); //true/false
})
.catch(function(error) {
console.log(error);
});