如何在 Cloudant 中查找过期文档?
我在 Cloudant 中有包含到期日期的文档,例如,
{
"_id": "a",
"name": "bob",
"expiry_date": "2022-06-05"
}
识别已过期文档以对其执行某些操作(例如删除它们)的最佳方法是什么?
I have documents in Cloudant which contain an expiry date, e.g.
{
"_id": "a",
"name": "bob",
"expiry_date": "2022-06-05"
}
What is the best way to identify documents that have expired to perform some action them, e.g. delete them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,理想的方法是构建一个发出到期日期的视图:
因此,如果您想要过期的文档,您可以使用此视图来查询数据集并查找到期日期在今天之前的文档。您将传入以下参数:
您的查询 URL 将如下所示:
/<数据库>/_design//_view/?include_docs=true&startkey="0000-00-00"&endkey="2022-03-16"
它将按
expiry_date
顺序返回所有匹配的文档The ideal way in this case is to build a view that emits the expiration date:
So then if you want expired documents you can use this view to query the dataset and find documents whose expiry date is before today. You would pass in the following parameters:
Your query URL would look something like this:
/<database>/_design/<design_doc_name>/_view/<view_name>?include_docs=true&startkey="0000-00-00"&endkey="2022-03-16"
It would return all the matching documents in
expiry_date
order