(self, keys, index_options)
Internal create index helper.

        :Parameters:
          - `keys`: a list of tuples [(key, type), (key, type), ...]
          - `index_options`: a dict of index options.
Internal create index helper.
Internal create index helper .
def __create_index(self, keys, index_options):
        """Internal create index helper.

        :Parameters:
          - `keys`: a list of tuples [(key, type), (key, type), ...]
          - `index_options`: a dict of index options.
        """
        index_doc = helpers._index_document(keys)
        index = {"key": index_doc}
        collation = validate_collation_or_none(
            index_options.pop('collation', None))
        index.update(index_options)

        with self._socket_for_writes() as sock_info:
            if collation is not None:
                if sock_info.max_wire_version < 5:
                    raise ConfigurationError(
                        'Must be connected to MongoDB 3.4+ to use collations.')
                else:
                    index['collation'] = collation
            cmd = SON([('createIndexes', self.name), ('indexes', [index])])
            try:
                self._command(
                    sock_info, cmd, read_preference=ReadPreference.PRIMARY,
                    codec_options=_UNICODE_REPLACE_CODEC_OPTIONS,
                    write_concern=self.write_concern,
                    parse_write_concern_error=True)
            except OperationFailure as exc:
                if exc.code in common.COMMAND_NOT_FOUND_CODES:
                    index["ns"] = self.__full_name
                    wcn = (self.write_concern if
                           self.write_concern.acknowledged else WriteConcern())
                    self.__database.system.indexes._insert(
                        sock_info, index, True, False, False, wcn)
                else:
                    raise
def __create_index ( self , keys , index_options ) : index_doc = helpers . _index_document ( keys ) index = { "key" : index_doc } collation = validate_collation_or_none ( index_options . pop ( 'collation' , None ) ) index . update ( index_options ) with self . _socket_for_writes ( ) as sock_info : if collation is not None : if sock_info . max_wire_version < 5 : raise ConfigurationError ( 'Must be connected to MongoDB 3.4+ to use collations.' ) else : index [ 'collation' ] = collation cmd = SON ( [ ( 'createIndexes' , self . name ) , ( 'indexes' , [ index ] ) ] ) try : self . _command ( sock_info , cmd , read_preference = ReadPreference . PRIMARY , codec_options = _UNICODE_REPLACE_CODEC_OPTIONS , write_concern = self . write_concern , parse_write_concern_error = True ) except OperationFailure as exc : if exc . code in common . COMMAND_NOT_FOUND_CODES : index [ "ns" ] = self . __full_name wcn = ( self . write_concern if self . write_concern . acknowledged else WriteConcern ( ) ) self . __database . system . indexes . _insert ( sock_info , index , True , False , False , wcn ) else : raise