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

Method index_information

pymongo/synchronous/collection.py:2593–2633  ·  view source on GitHub ↗

Get information on this collection's indexes. Returns a dictionary where the keys are index names (as returned by create_index()) and the values are dictionaries containing information about each index. The dictionary is guaranteed to contain at least a single key, `

(
        self,
        session: Optional[ClientSession] = None,
        comment: Optional[Any] = None,
    )

Source from the content-addressed store, hash-verified

2591 )
2592
2593 def index_information(
2594 self,
2595 session: Optional[ClientSession] = None,
2596 comment: Optional[Any] = None,
2597 ) -> MutableMapping[str, Any]:
2598 """Get information on this collection's indexes.
2599
2600 Returns a dictionary where the keys are index names (as
2601 returned by create_index()) and the values are dictionaries
2602 containing information about each index. The dictionary is
2603 guaranteed to contain at least a single key, ``"key"`` which
2604 is a list of (key, direction) pairs specifying the index (as
2605 passed to create_index()). It will also contain any other
2606 metadata about the indexes, except for the ``"ns"`` and
2607 ``"name"`` keys, which are cleaned. Example output might look
2608 like this:
2609
2610 >>> db.test.create_index("x", unique=True)
2611 'x_1'
2612 >>> db.test.index_information()
2613 {'_id_': {'key': [('_id', 1)]},
2614 'x_1': {'unique': True, 'key': [('x', 1)]}}
2615
2616 :param session: a
2617 :class:`~pymongo.client_session.ClientSession`.
2618 :param comment: A user-provided comment to attach to this
2619 command.
2620
2621 .. versionchanged:: 4.1
2622 Added ``comment`` parameter.
2623
2624 .. versionchanged:: 3.6
2625 Added ``session`` parameter.
2626 """
2627 cursor = self._list_indexes(session=session, comment=comment)
2628 info = {}
2629 for index in cursor:
2630 index["key"] = list(index["key"].items())
2631 index = dict(index) # noqa: PLW2901
2632 info[index.pop("name")] = index
2633 return info
2634
2635 def list_search_indexes(
2636 self,

Callers 15

test_create_indexesMethod · 0.45
test_create_indexMethod · 0.45
test_drop_indexMethod · 0.45
test_index_infoMethod · 0.45
test_index_geo2dMethod · 0.45
test_index_textMethod · 0.45
test_index_2dsphereMethod · 0.45

Calls 3

_list_indexesMethod · 0.95
itemsMethod · 0.80
popMethod · 0.45

Tested by 15

test_create_indexesMethod · 0.36
test_create_indexMethod · 0.36
test_drop_indexMethod · 0.36
test_index_infoMethod · 0.36
test_index_geo2dMethod · 0.36
test_index_textMethod · 0.36
test_index_2dsphereMethod · 0.36