title: Insert json file into mongodb using a variable
body: <p>I am trying to insert a json file into mongodb. When I enter the JSON directly into the insert statement, it works fine.  However, when I try to use the data variable from fs.readfile (same JSON) The insert fails.  I don't get an error, just now data in the collection when I use a variable instead of the raw JSON.  Here's the code..</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient
      , format = require('util').format;
  
  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
      if(err) throw err;
  
   var fs = require('fs');
  var mydocuments = fs.readFile('testNames.json', 'utf8', function (err, data) {
      var collection = db.collection('contactCollection');
       collection.insert(data, function(err, docs) { //This insert Fails
          collection.count(function(err, count) {
              console.log(format("count = %s", count));
              console.log("[" + data + "]" );
              db.close();
          });
      });
  
  var MongoClient = require('mongodb').MongoClient
      , format = require('util').format;
  
  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
      if(err) throw err;
  
   var fs = require('fs');
  var mydocuments = fs.readFile('testNames.json', 'utf8', function (err, data) {
      var collection = db.collection('contactCollection');
       collection.insert({firstname: "Bill"}, function(err, docs) { //This insert succeeds
          collection.count(function(err, count) {
              console.log(format("count = %s", count));
              console.log("[" + data + "]" );
              db.close();
          });
      });
  </code></pre>