0

Overview

I read from a .csv file, convert to JSON. Then I call my mongoinsert() function and insert that JSON data into mongodb

    function clean(){
      var options = {
        delimiter:',',
        quote:'"'
      };
      var data = fs.readFile('st.csv','utf8',function(err,data){
        objectArray=csvjson.toObject(data,options);
        mongoInsert();
      });
    }
    clean();

mongoinsert()

is my function to which I connect to mongodb; here is where I run into a problem
    function mongoInsert(){
      var url = "mongodb://localhost:9999/test";
      console.log("insert function");
      MongoClient.connect(url,function(err,db){
        db.collection('people').insertOne({'name':'jc'});
      });
    }

Note: I'm passing {'name':'jc'} for testing

sending error: 'type error db.collection is not a function'

I've printed out the the db object itself but it seems that the collection method does not exist. I'm wondering if it's node's asynchronous model, I'm just implementing it incorrectly.

0 Answers0