Skip to main content
Firestore Pydantic ODM ships three str-based enums that act as the vocabulary for batch writes, query filters, and result ordering. Because every member inherits from str, enum values can be passed directly wherever Firestore’s Python client expects a plain string — no extra conversion step needed.

BatchOperation

BatchOperation identifies the kind of atomic write to perform when you pass a list of operations to batch_write(). Each operation is expressed as a two-element tuple: (BatchOperation, model_instance).
When using BatchOperation.CREATE, the id field on the model instance may be None. The batch writer will auto-assign a Firestore document ID and write it back to model_instance.id before committing. For UPDATE and DELETE, id must already be set.

FirestoreOperators

FirestoreOperators enumerates every comparison and membership operator supported by Firestore queries. You typically encounter these indirectly — the FirestoreField descriptor produces them automatically when you use Python’s built-in comparison syntax. However, you can also reference them directly when constructing raw filter tuples.
Prefer the FirestoreField comparison syntax (User.age >= 18) over raw tuples. It is less error-prone and keeps your query logic coupled to the model definition, so a renamed field is caught at development time rather than at runtime.

OrderByDirection

OrderByDirection specifies whether results should be returned in ascending or descending order when an order_by parameter is supplied to find(), find_one(), or their collection-group equivalents. OrderByDirection overrides __str__ to return the raw value, so it integrates cleanly with the Firestore Python client’s direction keyword argument without any manual coercion.
When an order_by entry is a bare field rather than a tuple — for example, just User.name — Firestore applies its default ascending order. Wrap the field in a tuple with OrderByDirection.ASCENDING if you want to be explicit.