0

我可以以某种方式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
4

1 回答 1

0

MongoAlchemy 0.13 没有提供索引过期时间的可能性。我们需要直接使用 PyMongo 来做。

于 2012-10-21T06:45:53.067 回答