UNPKG

hera-mongo-tools

Version:
74 lines (73 loc) 2.38 kB
var ssync = require('child_process').spawnSync; module.exports = class HeraMongoTools { constructor(options) { this.options = options; this.ssync = ssync; } mongodump(callback) { try { if ("showCommand" in this.options && this.options.showCommand === true) { console.log(this.showCommand("mongodump")); } if ("command" in this.options) { var restore = this.ssync("mongodump", this.options.command); if (restore.status == 0) { callback(true); } else { callback(false); } } else { callback(false); } } catch (error) { callback(false); } } mongoimport(callback) { try { if ("showCommand" in this.options && this.options.showCommand === true) { console.log(this.showCommand("mongoimport")); } if ("command" in this.options) { var restore = this.ssync("mongoimport", this.options.command); if (restore.status == 0) { callback(true); } else { callback(false); } } else { callback(false); } } catch (error) { callback(false); } } mongorestore(callback) { try { if ("showCommand" in this.options && this.options.showCommand === true) { console.log(this.showCommand("mongorestore")); } if ("command" in this.options) { var restore = this.ssync("mongorestore", this.options.command); if (restore.status == 0) { callback(true); } else { callback(false); } } else { callback(false); } } catch (error) { callback(false); } } showCommand(com) { let command = com + " "; if ("command" in this.options) { this.options.command.forEach(element => { command += element + " "; }); } return command; } }