如何在MongoDB中获取TTL或过期的文档?
我想创建票务系统。在给定时间段内,在哪里取消票证?。但是,在它到期或在该特定机票到期之前,我想检验或将其保存在不同的集合中以备将来使用MongoDB吗?
I want to create ticketing system . Where ticket get cancelled after given period of time ?.For deleting after some time I am going to use indexing feature by MongoDb . But before it gets expire or after the expiry of that particular ticket I want to retrive or save it in different collection for future is it possible using mongodb ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在当前版本的MongoDB中,我写这篇文章时,它并不直接支持,但它将在mongodb 6.0中(cf this jira票),在此期间,您可以使用一个解决方法(继续阅读!)。
让我解释一下。您要做的是:
在5.0.8中,此变更流事件将仅包含已删除文档的
_id
字段,而没有其他内容,因为这是OPLOG中当前可用的唯一信息。在6.0中,您将能够访问本文档的先前状态(因此在删除之前是最后一个状态)。
话虽这么说,帕维尔·杜乔夫尼(Pavel Duchovny)在他的博客文章。您可以轻松地容纳他的通知系统以实现您所需的行为。
In the current version of MongoDB, 5.0.8 as I'm writing this, it's not directly supported, but it will be in MongoDB 6.0 (CF this jira ticket) and there is a workaround that you can use in the meantime (keep reading!).
Let me explain. What you are trying to do is:
In 5.0.8, this change stream event will only contain the
_id
field of the deleted document, and nothing else, as that's the only information currently available in the oplog.In 6.0, you will be able to access the previous state of this document (so it's last state before being deleted).
That being said, there is a workaround that Pavel Duchovny explained in his blog post. You can easily accommodate his notification system to achieve your desired behaviour.