You need to create a composite index and set unique to True , as stated in the documentation :
If you use a unique constraint for a composite index, MongoDB will apply uniqueness in a combination of values, rather than a single value for any or all of the key values.
self.db[self.mongo_collection].create_index( [("url", pymongo.DESCENDING), ("category", pymongo.ASCENDING)], unique=True )
source share