我可以以某种方式expireAfterSeconds
在 MongoAlchemy 中指定集合的索引,或者我需要像这样进行破解:
class TtlIndex(Index):
def expires(self, seconds):
self.expireAfterSeconds = seconds
def ensure(self, collection):
extras = {}
if self.__min is not None:
extras['min'] = self.__min
if self.__max is not None:
extras['max'] = self.__max
if self.__bucket_size is not None:
extras['bucket_size'] = self.__bucket_size
if self.expireAfterSeconds:
extras['expireAfterSeconds'] = self.expireAfterSeconds
collection.ensure_index(self.components, unique=self.__unique,
drop_dups=self.__drop_dups, **extras)
return self