title: How to fetch data from mongodb and convert it to json object in node.js?
body: <p>I want to fetch the data from mongo db and store it in a json object in node.js. The purpose is to manipulate that data which I think is quite simple if its a json objcet.
  Below is the code I am using:</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  var ObjectId = require('mongodb').ObjectID;
  var url = 'mongodb://localhost:27017/MyCollection';
  
  var data;
  
  var findRestaurants = function (db, callback) {
      var cursor = db.collection('demographicdetails').find().limit(10);
  
      cursor.each(function (err, doc) {
  
          if (doc != null) {
              console.dir(doc);
  
          } else {
              callback();
          }
      });
  };
  
  MongoClient.connect(url, function (err, db) {
  
      findRestaurants(db, function () {
          db.close();
      });
  });
  </code></pre>
  
  <p>From above code, I am able to fetch the data from mongo db and <code>console.dir(doc)</code> shows me the data.</p>
  
  <p>What I want to do is something like this:</p>
  
  <pre><code>  data = doc;
   data.forEach(function (eval) {
       //Manipulating eval
   });
  </code></pre>
  
  <p>Please suggest. Thanks in advance!</p>