Closed partyzan closed 5 years ago
Haven't messed with expiring collections at all.. :) Should be possible to add an expiration to a field index. Right now we only support unique indexes.
Got it, thanks for the answer.
@partyzan how did you implement it?
@FPurchess we implemented it ourselves - added a common base class
class DocumentWithIndexes(Document):
import pymongo
ASCENDING = pymongo.ASCENDING
DESCENDING = pymongo.DESCENDING
def __init__(self, alias=None, **kwargs):
indexes = self.__indexes__ if hasattr(self, "__indexes__") else []
if len(indexes) == 0:
return
def ensure_index(index, **spec):
self.objects.coll(alias).ensure_index(index, **spec)
for index_spec in indexes:
ensure_index(**index_spec)
super().__init__(**kwargs)
All our documents inherit from this base class and define their indexes. For example:
class BlacklistTokenRecord(Document):
__collection__ = "revoked-tokens"
__indexes__ = [
{"index": "created_at", "expireAfterSeconds": 3600},
{"index": "token_id", "unique": True}
]
token_id = UUIDField(required=True)
created_at = DateTimeField(required=True, default=datetime.utcnow)
Does motorengine support expiring collections as described in http://docs.mongodb.org/manual/tutorial/expire-data/ ?
Looks like mongoengine uses the following :
I tried the same but it didn't work, is there a way to set ttl index through motorengine ?