从 couch-db 中获取未删除的文档更改连续提要
Fetch non deleted documents from couch-db changes continuous feed
我正在寻找一种方法来从 CouchDB 中获取未删除文档的连续提要。
Lightcouch jar 具有我正在使用的连续进纸功能,但它会检索所有文档,包括已删除的文档。
目前,我正在阅读所有文档并添加了一个文件
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.continuousChanges();
我找到了一种解决方法来读取所有内容并过滤掉已删除的内容,但这似乎不是最好的方法。
Flux
.interval(Duration.ofMillis(1000))
.map(intervalTicking -> changes)
.filter(Changes::hasNext)
.map(Changes::next)
.filter(row -> !row.isDeleted())
...
如果有更好的选择,请提出建议。
提前致谢。
为了从更改提要中过滤未删除的文档,您应该在数据库的设计文档中定义一个过滤器,如下所示,其中定义了过滤器 "active-doc"。
{
"_id": "_design/filters",
"language": "javascript",
"filters": {
"active-doc": "function(doc, req){\n return (!doc._deleted);\n}\n"
}
}
在 LightCouch 中,您可以在更改源配置中包含过滤器。
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.filter("filters/active-doc")
.continuousChanges();
现在您应该只会收到来自未删除文档的更改事件。
作为替代方案,您可以使用 LightCouch 的 fork,其中支持芒果选择器用于更改源。使用 fork,您无需在数据库中创建设计文档,只需在您的客户端中指定选择器即可。
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.selector("{\"selector\": { \"_deleted\": {\"$exists\": false}}}")
.continuousChanges();
我正在寻找一种方法来从 CouchDB 中获取未删除文档的连续提要。
Lightcouch jar 具有我正在使用的连续进纸功能,但它会检索所有文档,包括已删除的文档。
目前,我正在阅读所有文档并添加了一个文件
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.continuousChanges();
我找到了一种解决方法来读取所有内容并过滤掉已删除的内容,但这似乎不是最好的方法。
Flux
.interval(Duration.ofMillis(1000))
.map(intervalTicking -> changes)
.filter(Changes::hasNext)
.map(Changes::next)
.filter(row -> !row.isDeleted())
...
如果有更好的选择,请提出建议。
提前致谢。
为了从更改提要中过滤未删除的文档,您应该在数据库的设计文档中定义一个过滤器,如下所示,其中定义了过滤器 "active-doc"。
{
"_id": "_design/filters",
"language": "javascript",
"filters": {
"active-doc": "function(doc, req){\n return (!doc._deleted);\n}\n"
}
}
在 LightCouch 中,您可以在更改源配置中包含过滤器。
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.filter("filters/active-doc")
.continuousChanges();
现在您应该只会收到来自未删除文档的更改事件。
作为替代方案,您可以使用 LightCouch 的 fork,其中支持芒果选择器用于更改源。使用 fork,您无需在数据库中创建设计文档,只需在您的客户端中指定选择器即可。
Changes changes = dbClient.changes()
.includeDocs(true)
.since(0)
.heartBeat(1000)
.selector("{\"selector\": { \"_deleted\": {\"$exists\": false}}}")
.continuousChanges();