Module motor_odm.indexes
¶
-
class
motor_odm.indexes.
IndexManager
(collection: motor.core.AgnosticCollection, session: motor.core.AgnosticClientSession, **kwargs: Any)¶ Bases:
object
An
IndexManager
instance can create a specific state concerning indexes.Note
The
IndexManager
is 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
indexes
exist in the databse.This method communicates with the database several times to compare the specified
indexes
to 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
indexes
will be dropped unlessdrop=False
is specified.
-
static
equal
(index: pymongo.operations.IndexModel, db_index: bson.son.SON) → bool¶ Compares the specified
index
anddb_index
.This method return
True
if theindex
specification can be considered equal to the existingdb_index
in 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
None
if no index matchingspec
exists.
-
async