giliev giliev - 3 months ago 22
Python Question

Expire index in mongoDB based on condition

I have

boolean
field named
pending
in
Mongoengine
model in Python. I want the document to be removed after 1 hour only if
pending=True
. If I needed to remove the document after 1 hour unconditionally I would just set expire index. Is there some smart and easy way to add some conditional check to expire index?

Thank you in advance!

Answer

I am afraid it is not directly possible to add some custom logic to the periodic cleaning of expired documents but as described in the docs you could use a expire index and only set the indexed field from your application if pending = True - as documents without the field of the expire index are not removed this should work although not exactly what you requested.

Comments