Skip to content

daimenworrall/mongoutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mongoutils

Intro

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.

Including

const mongoutils = require('@seiren/mongoutils');

API

parseMongoUrl(url)

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);

createDumpCommand(parsedUrl, outDir)

Generate the mongodump command.

  let command = mongoutils.createDumpCommand(info, './dump');

createRestoreCommand(parsedUrl, inDir)

Generate the mongorestore command.

  let command = mongoutils.createRestoreCommand(info, './dump/test');

executeCommand(command)

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.

checkInstalled()

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);
    });

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published