# Binary

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**](https://docs.mongodb.com/manual/reference/limits/#bson-documents) to 16MB per document. For storage of binray data beyond this limit please utilize [GridFS](https://docs.mongodb.com/manual/core/gridfs/index.html) support.

### Import

`from marrow.mongo.field import Binary`

### Inherits

`marrow.mongo:`**`Field`**

## Attributes

This field type inherits all [`Field` attributes](https://github.com/marrow/mongo/tree/128b1ec81ec6a48e05a95c32b636deede377854b/reference/field/field.md#attributes) and represents a singular, scalar binary string value. It has no specific configuration options.

## Usage

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.

## Example

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.

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

me = User("amcgregor")

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

me.insert_one()
```

## See Also

* [`String`](/reference/fields/string.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mongo.webcore.io/reference/fields/binary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
