(self)
Get a cursor over the index documents for this collection.

          >>> for index in db.test.list_indexes():
          ...     print(index)
          ...
          SON([(u'v', 1), (u'key', SON([(u'_id', 1)])),
               (u'name', u'_id_'), (u'ns', u'test.test')])

        :Returns:
          An instance of :class:`~pymongo.command_cursor.CommandCursor`.

        .. versionadded:: 3.0
Get a cursor over the index documents for this collection.
Get a cursor over the index documents for this collection .
def list_indexes(self):
        """Get a cursor over the index documents for this collection.

          >>> for index in db.test.list_indexes():
          ...     print(index)
          ...
          SON([(u'v', 1), (u'key', SON([(u'_id', 1)])),
               (u'name', u'_id_'), (u'ns', u'test.test')])

        :Returns:
          An instance of :class:`~pymongo.command_cursor.CommandCursor`.

        .. versionadded:: 3.0
        """
        codec_options = CodecOptions(SON)
        coll = self.with_options(codec_options)
        with self._socket_for_primary_reads() as (sock_info, slave_ok):
            cmd = SON([("listIndexes", self.__name), ("cursor", {})])
            if sock_info.max_wire_version > 2:
                try:
                    cursor = self._command(sock_info, cmd, slave_ok,
                                           ReadPreference.PRIMARY,
                                           codec_options)["cursor"]
                except OperationFailure as exc:
                    # Ignore NamespaceNotFound errors to match the behavior
                    # of reading from *.system.indexes.
                    if exc.code != 26:
                        raise
                    cursor = {'id': 0, 'firstBatch': []}
                return CommandCursor(coll, cursor, sock_info.address)
            else:
                namespace = _UJOIN % (self.__database.name, "system.indexes")
                res = helpers._first_batch(
                    sock_info, self.__database.name, "system.indexes",
                    {"ns": self.__full_name}, 0, slave_ok, codec_options,
                    ReadPreference.PRIMARY, cmd,
                    self.database.client._event_listeners)
                data = res["data"]
                cursor = {
                    "id": res["cursor_id"],
                    "firstBatch": data,
                    "ns": namespace,
                }
                # Note that a collection can only have 64 indexes, so we don't
                # technically have to pass len(data) here. There will never be
                # an OP_GET_MORE call.
                return CommandCursor(
                    coll, cursor, sock_info.address, len(data))
def list_indexes ( self ) : codec_options = CodecOptions ( SON ) coll = self . with_options ( codec_options ) with self . _socket_for_primary_reads ( ) as ( sock_info , slave_ok ) : cmd = SON ( [ ( "listIndexes" , self . __name ) , ( "cursor" , { } ) ] ) if sock_info . max_wire_version > 2 : try : cursor = self . _command ( sock_info , cmd , slave_ok , ReadPreference . PRIMARY , codec_options ) [ "cursor" ] except OperationFailure as exc : # Ignore NamespaceNotFound errors to match the behavior # of reading from *.system.indexes. if exc . code != 26 : raise cursor = { 'id' : 0 , 'firstBatch' : [ ] } return CommandCursor ( coll , cursor , sock_info . address ) else : namespace = _UJOIN % ( self . __database . name , "system.indexes" ) res = helpers . _first_batch ( sock_info , self . __database . name , "system.indexes" , { "ns" : self . __full_name } , 0 , slave_ok , codec_options , ReadPreference . PRIMARY , cmd , self . database . client . _event_listeners ) data = res [ "data" ] cursor = { "id" : res [ "cursor_id" ] , "firstBatch" : data , "ns" : namespace , } # Note that a collection can only have 64 indexes, so we don't # technically have to pass len(data) here. There will never be # an OP_GET_MORE call. return CommandCursor ( coll , cursor , sock_info . address , len ( data ) )