title: Upload file (size <16MB) to MongoDB
body: <p>I have a requirement to upload file to MongoDB. Currently I am saving files in a folder in current filesystem using Flask. Is there a way I can upload file to MongoDB without using GridFS? I believe I did something like this long before but I cannot recollect since its been longtime since I last used MongoDB.</p>
  
  <p>Any file I select to upload is no more than 16MB in size.</p>
  
  <p>Update: I tried this to convert image file using <code>binData</code> but it throws error <code>global name binData is not defined</code>.</p>
  
  <pre><code>import pymongo
  import base64
  import bson
  
  # establish a connection to the database
  connection = pymongo.MongoClient()
  
  #get a handle to the test database
  db = connection.test
  file_meta = db.file_meta
  file_used = "Headshot.jpg"
  
  def main():
      coll = db.sample
      with open(file_used, "r") as fin:
          f = fin.read()
          encoded = binData(f)
  
      coll.insert({"filename": file_used, "file": f, "description": "test" })
  </code></pre>