0
我可以採用某種指定expireAfterSeconds
收集在MongoAlchemy索引或我需要破解這樣的:設置TTL在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
我對mongoalchemy並不是特別熟悉,但是這是下降到pymongo,對不對?那有什麼問題? – shelman
@shelman,是的,它的確如此。非常奇怪的是,確保方法並不需要kwargs調用PyMongo的'collection.ensure_index'。似乎是因爲它現在的版本是0.13。我檢查了它的代碼和文檔,並決定使用它爲時過早。 – Marboni