【问题标题】:Settings TTL in MongoAlchemy's Index在 MongoAlchemy 的索引中设置 TTL
【发布时间】:2012-10-18 15:29:19
【问题描述】:

我能否以某种方式为 MongoAlchemy 中的集合索引指定 expireAfterSeconds,或者我需要像这样进行破解:

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,是的,确实如此。很奇怪,确保方法没有使用 kwargs 来调用 PyMongo 的 collection.ensure_index。似乎是因为它的当前版本现在是 0.13。我检查了它的代码和文档,并认为现在使用它还为时过早。

标签: python mongodb mongoalchemy


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-07
    • 2021-11-16
    • 2013-09-04
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多