CouchDB Filtered Replication无法正常工作

时间:2018-01-17 10:57:05

标签: couchdb pouchdb

我在客户端使用PouchDB,在服务器端使用CouchDB。我的客户端需要使用过滤器从服务器复制数据。

这是我正在使用的客户端代码:

_db.replicate.from(_remote_db, {
                filter: "repl/myfilter",
                live: false,
                retry: true,
                query_params: {
                    group: '11'
                }
            }).on('change', (info) => {
                dbReplChangeHandler(_db, _db_analytics, info, deferred);
            })

couchDB数据库中的设计文档是:

   {
  "_id": "_design/repl",
  "_rev": "19-3848f574d651345540379c06b67699bb",
  "filters": {
    "myfilter": "function (doc, req){return true;}"
  }
}

客户端仍然无法从服务器复制此错误timeout,{gen_server,call,\n [couch_proc_manager,}

1 个答案:

答案 0 :(得分:0)

这个问题似乎与couchdb 2.1.1有关(我在Mac上确认了这种行为,不知道它是否存在于其他平台上)。重现起来非常简单:

1)创建测试数据库

curl -vX PUT http://localhost/testdb

2)填充文件

for i in {1..5}; do curl -vX PUT http://localhost/testdb/00$i -d '{"type":"A", "description":"Document 00$i"}'; done;

3)测试你可以看到文件

curl -X GET http://localhost/testdb/_changes?since=0

您会看到类似于以下内容的输出:

{"results":[
{"seq":"3-g1AAAAB5eJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZE5FyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPMi2RIQsAx5cmmw","id":"001","changes":[{"rev":"3-c9fb50f5d39cdac66a342dfac914fc52"}]},
{"seq":"4-g1AAAAB5eJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZElFyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPMi2RIQsAx-UmnA","id":"004","changes":[{"rev":"1-987569f1cc05eaf1bad8793d290adab2"}]},
{"seq":"5-g1AAAAB5eJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZE1FyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPMi2RIQsAyDMmnQ","id":"005","changes":[{"rev":"1-987569f1cc05eaf1bad8793d290adab2"}]},
{"seq":"7-g1AAAACbeJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZE1FyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPNY0JbFqaoVGSobkxNn1ZAHN1MJo","id":"002","changes":[{"rev":"1-987569f1cc05eaf1bad8793d290adab2"}]},
{"seq":"8-g1AAAACbeJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZE1FyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPNY0ZbFqaoVGSobkxNn1ZAHOXMJs","id":"003","changes":[{"rev":"1-987569f1cc05eaf1bad8793d290adab2"}]},
"last_seq":"9-g1AAAACbeJzLYWBgYMpgTmEQTM4vTc5ISXLIyU9OzMnILy7JAUklMiTV____PyuDOZE1FyjAnmiWlmhuaIhNAx5j8liAJEMDkPoPNY0FbFqaoVGSobkxNn1ZAHO5MJw","pending":0}

4)创建一个简单的“接受所有”'过滤

curl -vX PUT http://localhost/testdb/_design/test -d '{"filters":{"everything":"function(doc, req){return true;}"}}'

5)将过滤器应用于_changes命令

curl -X GET http://localhost/testdb/_changes?filter=test/everything&since=0

现在您将看到类似的内容:

{
    "error": "error",
    "reason": "{timeout,{gen_server,call,
               [couch_proc_manager,
        {get_proc,{doc,<<\"_design/test\">>,
{1,
[<<251,118,3,66,28,132,147,60,168,234,
101,119,87,97,205,255>>]},
{[{<<\"filters\">>,
{[{<<\"everything\">>,
<<\"function(doc, req){return true;}\">>}]}}]},
],false,[]},
{<<\"_design/test\">>,
<<\"1-fb7603421c84933ca8ea65775761cdff\">>}},
5000]}}"
}

这是2.1.1版本,我已经确认版本2.1.1-1(尚未发布)可以工作(至少在这种情况下),您可以找到here。< / p>

如果您的问题发生在Windows或Linux上,您可能希望降级到2.1.0或2.0版。

希望这有帮助