Module motor_odm.indexes¶
-
class
motor_odm.indexes.IndexManager(collection: motor.core.AgnosticCollection, session: motor.core.AgnosticClientSession, **kwargs: Any)¶ Bases:
objectAn
IndexManagerinstance can create a specific state concerning indexes.Note
The
IndexManageris used internally byDocument. Normally there is no need to use this class manually.-
async
ensure_indexes(indexes: Iterable[pymongo.operations.IndexModel], drop: bool = True) → None¶ Ensures that the specified
indexesexist in the databse.This method communicates with the database several times to compare the specified
indexesto the indexes already present in the database. If an index already exists it is not recreated. If an index exists with different options (name, uniqueness, …) it is dropped and recreated.Any indexes in the database that are not specified in
indexeswill be dropped unlessdrop=Falseis specified.
-
static
equal(index: pymongo.operations.IndexModel, db_index: bson.son.SON) → bool¶ Compares the specified
indexanddb_index.This method return
Trueif theindexspecification can be considered equal to the existingdb_indexin the database.
-
get_db_index(spec: bson.son.SON) → Optional[bson.son.SON]¶ Fetches the database index matching the
spec.This method does not communicate with the database. You have to have called
load_db_indexes()before.- Returns
An index from the database or
Noneif no index matchingspecexists.
-
async