I am new to node.js, I am able to store the csv data in mongodb but my 
approach is when the user upload a file and hit the submit button it will 
automatically stored in mongodb. can any one suggest how to overcome the 
task?
please help me thanks



var fs= require('fs');
var csv = require('fast-csv');

var mongodb = require('mongodb');
var url = 'mongodb://localhost:27017/CSVDATA';
var MongoClient = mongodb.MongoClient;


var data;

MongoClient.connect(url, function (err, db) {
if (err) {
  console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
  console.log('Connection established to', url);
  var collection = db.collection('INFORMATION');
  readData=fs.createReadStream('data.csv').pipe(csv())
               .on('data',function(data){

                  collection.insert({'data':data})

               })
               .on('end',function(data){
                  console.log('Read finished');
               })

}
});




down vote

down votefavoritI am able to store the csv data in mongodb but my approach 
is when the user upload a file and hit the submit button it will 
automatically stored in mongodb. can any one suggest how to overcome the 
task? 
<https://stackoverflow.com/questions/49938546/how-to-submit-and-store-the-csv-file-in-mongodb?noredirect=1#>
favoritI am able to store the csv data in mongodb but my approach is when 
the user upload a file and hit the submit button it will automatically 
stored in mongodb. can any one suggest how to overcome the task? 
<https://stackoverflow.com/questions/49938546/how-to-submit-and-store-the-csv-file-in-mongodb?noredirect=1#>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/e4b91b00-9c43-484f-9fc0-b975e2008ad3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to