title: How to store Images in MongoDB through pymongo?
body: <pre><code>from PIL import Image
  from bson import Binary
  
  img = Image.open('test.jpg')
  img = Binary(img)
  </code></pre>
  
  <p>throws an error stating <code>TypeError : data must be an instance of bytes</code></p>
  
  <p>Why does this happen? And how to resolve this to store the img to MongoDB?</p>