0

Can I somehow specify expireAfterSeconds for collection's index in MongoAlchemy or I need to make hack like this:

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
Marboni
  • 2,399
  • 3
  • 25
  • 42
  • I'm not especially familiar with mongoalchemy, but this is dropping down into pymongo, right? What is wrong with that? – shelman Oct 18 '12 at 19:34
  • @shelman, yes, it does. It's very strange, that ensure method didn't take kwargs to call PyMongo's `collection.ensure_index` with them. Seems it's because its current version is 0.13 now. I checked its code and docs and decided that it's too early to use it. – Marboni Oct 19 '12 at 06:10

1 Answers1

0

MongoAlchemy 0.13 didn't provide a possibility to index with expiration time. We need to use PyMongo directly to do it.

Marboni
  • 2,399
  • 3
  • 25
  • 42