【发布时间】: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