Problems with mongodb setting index

how can I set up an index query faster in mongodb?

 def open_spider(self, spider):
        self.Client = pymongo.MongoClient(self.MongodbHost, self.MongodbPort)
        self.Mongodb = self.Client[self.MongodbName]
        self.db = self.Mongodb[self.MongodbCollection]

    def process_item(self, item, spider):

        unique_charcter = re.findall("https://files.zsxq.com/(.*?)\?attname", item["file_url"])[0]

        key_word = {"unique_charcter": unique_charcter, "name": item["name"]}
        res = self.db.find(key_word)

        if len(list(res)) == 1:

            raise DropItem("Duplicate item found: %s" % item)
        else:

            self.db.insert({"unique_charcter": unique_charcter, "name": item["name"]})

            return item

    def close_spider(self, spider):
        self.Client.close()
        
        

now find () is not indexed. I want to query faster now. How to write indexing?

Aug.22,2021

the query for you should be:

db.<collection>.createIndex({unique_charcter: 1, name: 1})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39045-2c152.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39045-2c152.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?