Mongodb Set Index Problem

  mongodb, question

How to set up 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 () does not add index, I want to query faster now, how to add index?

The query for you should be:

db.<collection>.createIndex({unique_charcter: 1, name: 1})