I am trying to export a csv using node.js from mongodb. For this i started with this code:
app.get('/export', function(req, res) {
var spawn = require('child_process').spawn,
ls = spawn('mongoexport');
res.sendfile('/home/database.csv');
});
And this works fine. Then for making it more usable i tried to code below with mongoexport using arguments:
app.get('/export', function(req, res) {
var spawn = require('child_process').spawn,
ls = spawn('mongoexport --db lms --collection databases --fields firstname,lastname,email,daytimePhone,addressOne,city,state,postalCode,areaOfStudy,currentEducationLevel,company --csv --out /home/database.csv');
res.sendfile('/home/database.csv')
});
This throws a exception:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Then i tried using only one argument but it gives the same error :(
I tried this also to see if arguments work this way but the same error:
spawn('mongoexport',['--csv']);