title: mongoexport collection using node.js
body: <p>I am currently experiencing a major headache (for a middle-aged duffer, that is).
  My current problem is this:
  I have to use D3.js to visualise data stored in a local MongoDB database. I have the visualisation pretty much sorted, just one or two minors, but I think I can sort them.
  My problem is actually getting the data out of the database. I can import and export to my heart’s content using the shell, but I need to automate the process. The step I am having no progress with is this: Using Node.js, I can connect to my local MongoDB databse with the following script:</p>
  
  <pre><code>**
  
  var MongoClient = require('mongodb').MongoClient, format = require('util').format;
  MongoClient.connect('mongodb://127.0.0.1:27017' function(err,db){   
      if(err){
          throw err;
      }else{
          console.log("Connected");
      }
      db.close();
  });
  </code></pre>
  
  <p>**</p>
  
  <p>Whilst I am connected, I need to export one of three collections (newYork, manchester or london) , as a .json array, from a database called monopoly.
  I have to use javascript and I need to export an entire collection to a folder location that I can choose, which will allow me to direct my D3.js to it
  I think mongoexport is the method I want as when I try this from the mongo shell, I get exactly what I want
  Any enlightenment would be gratefully received
  Thanks
  S</p>