or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

bulk-operations.mdcustom-types.mddocuments.mdevents-actions.mdfields-types.mdindex.mdinitialization.mdmigrations.mdquery-operations.mdtime-series.md

custom-types.mddocs/

0

# Custom Types

1

2

Pydantic-compatible custom field types for MongoDB-specific data types like Decimal128 and Binary.

3

4

## Capabilities

5

6

### DecimalAnnotation

7

8

```python { .api }

9

DecimalAnnotation: TypeAlias

10

"""Pydantic annotation for handling BSON Decimal128 types."""

11

```

12

13

### BsonBinary

14

15

```python { .api }

16

BsonBinary: TypeAlias

17

"""Pydantic-compatible BSON binary field type."""

18

```

19

20

## Usage Examples

21

22

```python

23

from beanie import Document, DecimalAnnotation, BsonBinary

24

from decimal import Decimal

25

26

class Product(Document):

27

name: str

28

price: DecimalAnnotation # High-precision decimal

29

image_data: BsonBinary # Binary data

30

31

class Settings:

32

collection = "products"

33

34

# Create with custom types

35

product = Product(

36

name="Laptop",

37

price=Decimal("1299.99"),

38

image_data=b"binary_image_data"

39

)

40

await product.insert()

41

```