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)})
This blog is about things I encounter while doing web and non-web software development.