Binary fields store, as the name implies, raw binary data. This is the rough equivalent to a BLOB field in relational databases. The amount of storage space is limited to 16MB per document. For storage of binray data beyond this limit please utilize GridFS support.


from marrow.mongo.field import Binary




This field type inherits all Field attributes and represents a singular, scalar binary string value. It has no specific configuration options.


Instantiate and assign an instance of this class during construction of a new Document subclass. Accessing as a class attribute will return a Queryable allowing binary string filtering operations, and access as an instance attribute will return a bytes cast value.


Users may wish to utilize a "profile image" to identify themselves. Utilizing a Binary field (and appropriate upload limits) can facilitate this. When presenting back via HTTP, the mime type would be useful to track; see GridFS for this capability as well.

class User(Document):
    name = String('_id')
    avatar = Binary()

me = User("amcgregor")

with open('avatar.png', 'rb') as fh:
    me.avatar =


See Also

Last updated