pynenc_mongo.util.mongo_collections¶
Collection specifications for all MongoDB-based Pynenc components. Centralized location for all collection definitions and indexes.
Module Contents¶
Classes¶
Specification for a collection with its indexes |
|
Abstract base class for MongoDB collections with app_id-based prefix enforcement. |
Functions¶
Sanitize an app_id for safe use as a MongoDB collection name prefix. |
API¶
- pynenc_mongo.util.mongo_collections.sanitize_collection_prefix(app_id: str, max_prefix_len: int = 40) str[source]¶
Sanitize an app_id for safe use as a MongoDB collection name prefix.
Replaces any character that is not alphanumeric or underscore with an underscore, prepends an underscore if the result starts with a digit, then truncates to fit within
max_prefix_len(including an 8-character deterministic hash suffix). The hash is always computed from the full original app_id, so different app_ids that truncate to the same string still produce distinct prefixes.
- class pynenc_mongo.util.mongo_collections.CollectionSpec[source]¶
Specification for a collection with its indexes
- class pynenc_mongo.util.mongo_collections.MongoCollections(conf: pynenc_mongo.conf.config_mongo.ConfigMongo, prefix: str, app_id: str)[source]¶
Abstract base class for MongoDB collections with app_id-based prefix enforcement.
Initialization
- _prefixed_name(base_name: str) str[source]¶
Return the collection name prefixed with the sanitized app_id.
- instantiate_retriable_coll(spec: pynenc_mongo.util.mongo_collections.CollectionSpec) pynenc_mongo.util.mongo_client.RetryableCollection[source]¶
Instantiate a RetryableCollection for the given CollectionSpec.
Prepends the sanitized app_id prefix to the collection name so that different apps sharing the same database are fully isolated.
- Parameters:
spec – Specification for the collection
- Returns:
RetryableCollection instance