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 by Document. 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 unless drop=False is specified.

static equal(index: pymongo.operations.IndexModel, db_index: bson.son.SON)bool

Compares the specified index and db_index.

This method return True if the index specification can be considered equal to the existing db_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 matching spec exists.

async load_db_indexes()None

Loads the existing indexes from the database.