Using mongodb's TTL indexes

85 views
Skip to first unread message

Mikko Koskinen

unread,
Mar 15, 2017, 9:42:42 AM3/15/17
to Eve REST Framework
Hi,

I'd like to use mongodb's TTL idexes to auto-expire documents. This seems to work fine using Eve's mongo_indexes as follows.

# settings.py
my_resource = {
'mongo_indexes'
: {'expire_at': ([('expireAt', 1)], {"expireAfterSeconds": 0})},
'schema': { 'expireAt': { 'type': 'datetime' }}
}

It works fine as long as I have the 'expireAt' in the HTTP POST request payload.
What I'd like to do, however, is to define the expireAt on the server side. So I tried using the event hooks. With pre POST hook I can't modify the request, so it seems to be no go.
With pre insert db hook I am able to add 'expireAt' just fine but for some reason the TTL feature is not working in this case and the documents won't be automatically deleted.

Any idea how to get TTL working without client posting 'expireAt'?

-Mikko-

Mikko Koskinen

unread,
Mar 15, 2017, 3:40:15 PM3/15/17
to Eve REST Framework
I got it working with post POST event hook where I use patch_internal to update expireAt.
Reply all
Reply to author
Forward
0 new messages