CouchDB过滤器功能和连续供稿 [英] CouchDB filter function and continuous feed

查看:79
本文介绍了CouchDB过滤器功能和连续供稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于文档属性进行过滤的过滤器功能,例如版本: A ,它可以正常工作,直到在某个属性点版本: A 被删除(或更新为版本: B )。

I have a filter function filtering based on document property, e.g. "version: A" and it works fine, until there a document update at some point in time when this property "version: A" removed (or updated to "version: B").

在这一点上,我希望收到有关文档已更新的通知,类似于文档被删除时的更新,

At this point i would like to be notified that the document been updated, similar to one when the document get deleted, but couldn't find an effective way (without listening and processing all documents changes).

希望我只是缺少了一些东西,这不是设计上的限制。

Hope i'm just missing something and it's not a design limitation.

推荐答案

虽然我的其他答案是有效的方法,但昨天我遇到了同样的情况,并决定考虑使用Mango选择器进行这项工作。我执行了以下操作:

While my other answer is a valid approach, I had this same situation yesterday and decided to look at making this work using Mango selectors. I did the following:


  1. 建立由查询选择器过滤的变更供稿(请参阅 _selector过滤器,了解/ db / _changes)

  2. 执行查询(db / _find)并记录结果

  3. 建立第二个更改提要,仅对(2)中返回的文档进行过滤(请参见/ db / _changes的 _doc_ids过滤器)

(1)的供稿可让您知道新文档何时与您的查询以及对更改前后匹配查询的文档的编辑。

The feed at (1) lets you know when new documents match your query along with edits to documents that matched your query both before and after the change.

(2)的供稿可让您知道何时对文档进行了更改

The feed at (2) lets you know when a change is made to a document that previously matched your query, irrespective of if it matches your query after the change has been made.

这些供稿的组合涵盖了所有情况,尽管带有一些误报。如果更改了任一提要,请在(3)处拆下更改提要,然后重做步骤(2)和(3)。

The combination of these feeds covers all cases, though with some false positives. On a change in either feed, tear down the changes feed at (3) and redo steps (2) and (3).

现在,有关此方法的一些注意事项:

Now, some notes on this approach:


  • 这实际上仅适用于查询返回的文档数很小的情况,因为如果第二个提要中按_id进行过滤。

  • 如果第一个更改摘要中有很多更改,则必须注意确保正确建立第二个摘要。

  • 在某些情况下,两个提要中都会出现更改。最好避免做出两次反应。

  • 如果预计更改会频繁发生,那么如果您的客户不需要处理每一个更改通知,请使用防抖或速率限制。
  • li>
  • This is really only suitable in cases where the number of documents returned by the query is small because if the filtering by _id in the second feed.
  • Care must be taken to ensure that the second feed is established correctly if there are lots of changes coming in from the first changes feed.
  • There are cases where a change will appear in both feeds. It would be good to avoid reacting twice.
  • If changes are expected to happen frequently, then employ debouncing or rate limiting if your client does not need to process each and every change notification.

这种方法对我和我不得不处理的情况都很好。

This approach worked well for me and the cases I had to deal with.

参考文献:

  • http://docs.couchdb.org/en/stable/api/database/find.html
  • http://docs.couchdb.org/en/stable/api/database/changes.html

这篇关于CouchDB过滤器功能和连续供稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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