我在Python中的Mongoengine模型中有一个名为pending boolean字段。 我希望仅在pending=True后1小时后删除文档。 如果我需要在1小时后无条件删除文档,我只会设置过期索引。 是否有一些智能和简单的方法来添加一些条件检查到期索引?
先谢谢你!
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!
最满意答案
我担心不能直接在定期清理过期文档中添加一些自定义逻辑,但是如文档中所述,您可以使用过期索引,并且只在应用程序中设置索引字段(如果pending = True - 作为没有文档的文档过期索引的字段不会被删除这应该工作,虽然不完全是你所要求的。
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.
更多推荐
发布评论