如何在 Cloudant 中查找过期文档?

发布于 2025-01-14 17:06:45 字数 165 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑色毁心梦 2025-01-21 17:06:46

在这种情况下,理想的方法是构建一个发出到期日期的视图:

function (doc) {
  emit(doc.expiry_date);
}

因此,如果您想要过期的文档,您可以使用此视图来查询数据集并查找到期日期在今天之前的文档。您将传入以下参数:

  • startkey="0000-00-00"(时间的开始)
  • endkey="2022-03-16"(今天的日期)

您的查询 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:

function (doc) {
  emit(doc.expiry_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:

  • startkey="0000-00-00" (the beginning of time)
  • endkey="2022-03-16" (today's date)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文