javascript - NodeJs: executing a mongoshell with a js file of commands -
i wrote nodejs script has set of mongo commands. ran in terminal using following command , worked:
mongo --host 127.0.0.1:27017 data.js
it worked, performed operations need done.
afterwards, created nodejs file, automate script. executed same command using exec dependency.
var exec = require("child_process").exec; var execstring = "mongo --host 127.0.0.1:27017 " + config.file; exec(execstring, function(err, res){ if (err) { return cb(err); console.log("here") } else console.log("data import done"); });
config.file contains path js file. error received
{ error: command failed: mongo --host 127.0.0.1:27017 /opt/soajs/node_modules/soajs.utilities/data/artifact/data.js @ childprocess.exithandler (child_process.js:211:12) @ emittwo (events.js:106:13) @ childprocess.emit (events.js:191:7) @ maybeclose (internal/child_process.js:877:16) @ socket.<anonymous> (internal/child_process.js:334:11) @ emitone (events.js:96:13) @ socket.emit (events.js:188:7) @ pipe._handle.close [as _onclose] (net.js:501:12) killed: false, code: 253, signal: null, cmd: 'mongo --host 127.0.0.1:27017 /opt/soajs/node_modules. /soajs.utilities/data/artifact/data.js' }
Comments
Post a Comment