MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _create_index

Method _create_index

gridfs/asynchronous/grid_file.py:1174–1189  ·  view source on GitHub ↗
(
        self, collection: AsyncCollection[Any], index_key: Any, unique: bool
    )

Source from the content-addressed store, hash-verified

1172 object.__setattr__(self, "_buffered_docs_size", 0)
1173
1174 async def _create_index(
1175 self, collection: AsyncCollection[Any], index_key: Any, unique: bool
1176 ) -> None:
1177 doc = await collection.find_one(projection={"_id": 1}, session=self._session)
1178 if doc is None:
1179 try:
1180 index_keys = [
1181 index_spec["key"]
1182 async for index_spec in await collection.list_indexes(session=self._session)
1183 ]
1184 except OperationFailure:
1185 index_keys = []
1186 if index_key not in index_keys:
1187 await collection.create_index(
1188 index_key.items(), unique=unique, session=self._session
1189 )
1190
1191 async def _ensure_indexes(self) -> None:
1192 if not object.__getattribute__(self, "_ensured_index"):

Callers 1

_ensure_indexesMethod · 0.95

Calls 4

itemsMethod · 0.80
find_oneMethod · 0.45
list_indexesMethod · 0.45
create_indexMethod · 0.45

Tested by

no test coverage detected