title: TypeError: Cannot read property 'collection' of null ---node to insertData with mongoDb
body: <p><img src="https://i.stack.imgur.com/r7Y77.png" alt="image"></p>
  
  <p>this is my problem. now the code is below</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mongoClient = require('mongodb').MongoClient;
  var db = 'mongodb://localhost:27017/lcl';
  
  var insertData = function(db,callback){
   var collection = db.collection('user');
   var data = [{"name":"lcl","age":"23","sex":"男"},{"name":"王小猫","age":"22","sex":"女"}];
   collection.insert(data,function(err,result){
    if (err) {
     console.log(err);
     return;
    };
    callback(result);
   })
  }
  mongoClient.connect(db,function(err,db){
   console.log("连接成功");
   insertData(db,function(result){
    console.log(result);
    db.close();
   })
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>above is the code I have written.
  Please help me find the solution.</p>