Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
BeanieRepository is HexCore’s built-in async CRUD base for MongoDB, powered by Beanie ODM. It maps a typed domain entity T to a Beanie Document subclass D, handling entity_id remapping, logical deletes, and field-level transformations through optional resolver and serialiser maps.
BeanieRepository and all MongoDB symbols on this page require the hexcore[mongo] extra:Class hierarchy
BeanieRepository is also exported under the backward-compatible alias BeanieODMCommonImplementationsRepo.
BaseDocument
hexcore.infrastructure.repositories.orms.beanie.BaseDocument
Abstract Beanie Document base class that every collection document must extend. It adds standard audit fields and a unique entity_id index that bridges the MongoDB _id with your domain entity id.
Built-in fields
| Field | Type | Default | Notes |
|---|---|---|---|
entity_id | Annotated[UUID, Indexed(unique=True)] | required | Maps to the domain entity id |
created_at | Optional[datetime] | datetime.now() | Set at creation |
updated_at | Optional[datetime] | datetime.now() | Auto-updated via @after_event([Save]) |
is_active | Optional[bool] | True | Used for logical deletes |
Settings
init_beanie_documents()
hexcore.infrastructure.repositories.orms.beanie.utils.init_beanie_documents
BaseDocument that has been imported into the current Python process, then calls beanie.init_beanie() against the MongoDB URI configured in ServerConfig.mongo_uri. Call this once at application startup, after all document modules have been imported.
BeanieRepository
hexcore.infrastructure.repositories.implementations.BeanieRepository[T, D]
Full CRUD repository that maps a domain entity T to a Beanie document D. All methods are async.
Generic parameters
| Parameter | Bound | Description |
|---|---|---|
T | BaseEntity | Domain entity type returned by every method |
D | BaseDocument | Beanie document type used for MongoDB persistence |
Abstract properties to implement
The domain entity class used to reconstruct entities from documents via
model_construct.The Beanie document class used for all collection queries and writes.
Exception class (not instance) raised when a document is not found. Receives the queried
entity_id as its sole constructor argument.Optional properties
A mapping of
{ entity_field: (document_field, async_callable) } applied when converting a document to a domain entity. Each async callable receives the full document instance and must return the resolved value.A mapping of
{ entity_field: (document_field, callable) } applied when converting a domain entity to a document. Useful for embedding value objects or transforming complex types.When
True, list_all applies .skip(offset).limit(limit) to the Beanie query. Set to False to return all documents.Methods
Queries the collection for
{ "entity_id": entity_id }. Raises not_found_exception(entity_id) if no document is found.Returns all documents in the collection. When
limit_offset_pagination is True, applies .skip(offset).limit(limit).Executes a parameterised MongoDB query supporting full-text regex search, typed filters (
EQ, NE, GT, GTE, LT, LTE, IN, NOT_IN, CONTAINS, STARTSWITH, ENDSWITH, IS_NULL), sorting, and limit/offset pagination. Returns the page of results and the total matching document count.Decorated with
@register_entity_on_uow. Upserts the entity: if a document with matching entity_id exists, updates it; otherwise inserts a new document. Returns the re-hydrated entity. The entity.id field is mapped to document.entity_id on write and back to entity.id on read.Performs a logical delete: sets
document.is_active = False and calls document.save(). Documents are never physically removed.id ↔ entity_id remapping
MongoDB documents managed by HexCore store the domain entity’s UUID in the entity_id field (not _id). HexCore handles this remapping transparently:
| Direction | Mapping |
|---|---|
| Entity → Document (save) | entity.id → document.entity_id; MongoDB _id is auto-generated |
| Document → Entity (read) | document.entity_id → entity.id; _id is discarded |
Complete example
Repository discovery
Register your document/repository packages inServerConfig to enable auto-discovery:
config.py