title: How do I retrieve a Binary file from MongoDB after storing it?
body: <p>I store the file similar to the following:</p>
  
  <pre><code>var pdfBinary = fs.readFileSync("myfile.pdf");
  var invoice = {};
  invoice.pdf = new mongo.Binary(pdfBinary);
  </code></pre>
  
  <p>I then insert the above document into MongoDB. Then I try to retrieve it similar to the following:</p>
  
  <pre><code>    collection.findOne({}, function(err, retrievedPDF) {
          fs.writeFile("myretrieved.pdf", retrievedPDF.pdf.buffer, function(err) {
              ....
          });
  
      }); 
  </code></pre>
  
  <p>It comes out as a zero byte file. If I console.log the stored file it looks like the following:</p>
  
  <pre><code>{ pdf: 
   { _bsontype: 'Binary',
     sub_type: 0,
     position: 0,
     buffer: &lt;Buffer &gt; },
  _id: 53af545681a59758611937d7 }
  </code></pre>
  
  <p>I've gone through the documentation I find it somewhat confusing. What am I doing wrong that I cannot store/retrieve the file?</p>