1. b.93z.org
  2. Notes

pymongo and binary data in 2012

In 2010 we used pymongo.binary module to store binary data in MongoDB. Now BSON-related code is in separate package, therefore Binary class is now bson.binary.Binary.

So, saving binary data in MongoDB looks like this:

>>> from bson.binary import Binary
>>> some_data = b"123"
>>> some_collection.insert({"some_key": Binary(some_data)})

© 2008–2017 93z.org