根据条件使mongoDB中的索引过期(Expire index in mongoDB based on condition)

编程入门 行业动态 更新时间:2024-10-28 05:20:19
根据条件使mongoDB中的索引过期(Expire index in mongoDB based on condition)

我在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.

更多推荐

本文发布于:2023-04-27 13:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   条件   mongoDB   Expire   based

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!