我可以在长沙发文档的成员上使用TTL吗? [英] Can I use TTL on members on couchbase documents?

查看:41
本文介绍了我可以在长沙发文档的成员上使用TTL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计后端.我有一个json数组/队列/某物,我只需要不超过2周的任何数据,这些数据会不断地附加到数据上.我只想从此队列"中删除,而不要从容器文档中删除.我可以为此使用TTL,还是仅将TTL用于整个文档?

I'm designing my back-end. I have a json array/queue/something which I only need any data that is at most 2 weeks old, that is continuously appended to. I only want to delete from this "queue", but not the container document. Can I use TTL for this, or does TTL only work for whole documents?

是否有更好的方法来做到这一点?我应该将它们每天或每小时作为单独的文档存储吗?

Is there a better way to do this? Should I store them in per-day or per-hour arrays as separate documents instead?

正在运行沙发床2.2.

Running couchbase 2.2.

推荐答案

TTL仅适用于整个文档,无法使文档的子集过期.就像您说的那样,始终可以有不同的到期时间的单独文档,其中您具有类型,日期和数据数组作为元素.

TTL in Couchbase only applies to whole documents, it's not possible to expire subsets of a document. Like you said you can always have separate documents with different expiry times in which you have a type,date and then the array of data as an element.

然后使用如下视图:

function (doc, meta) {
  if(meta.type == "json") {
    if(doc.type == "ordered_data") {
      if(doc.date) {
        emit(dateToArray(doc.date)); 
      }
    }
  }
}

您可以发出按日期排序的所有相关数据(标志降序设置为true),它还允许您的应用通过传递一个或多个键来选择特定日期.IE.选择日期范围为2天,1周等.文档过期后,文档将在更新时从视图中删除(根据您陈旧的参数加上操作/秒的时间而变化).

You could emit all the related data ordered by date (flag descending set to true), it'd also allow your app to select specific dates by passing in one or more keys. I.e. selecting a date range of 2days,1week etc. When the document expires it'd be removed from the view when it updates (varies based upon your stale parameters plus ops a second/time).

然后,您可以在应用程序层进行所需的任何联接或额外处理.还有其他选择,但是对我来说,这是解决问题的最明智的方法,任何问题都请发表评论,我们将再次尝试.

Then you can do whatever joining or extra processing you need at the application layer. There are other options available but for me this would be the most sensible way to approach the problem, any problems just comment and we'll try again.

P.s.您要阵列多大?如果它们会很大,那么您可能需要考虑采用其他技术或方法来解决问题.

P.s. How big are you arrays going to become? If they are going to be very large then perhaps you'd need to look at a different tech or way to solve the problem.

这篇关于我可以在长沙发文档的成员上使用TTL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆