Android-Couchbase Lite-带过滤器提取-Replication.setFilter [英] Android - Couchbase lite - pull with filter - Replication.setFilter
问题描述
我正在使用android messagerie应用程序,消息存储在互联网上的CouchDB(Apache)数据库中。
如何在Android设备上提取带有过滤器的消息?
I'm working on a android messagerie app, messages are stored in a CouchDB(Apache) database on the internet. How can I pull messages with filter on my Android devices?
Android代码段:
Android Snippet:
Replication pull = new Replication(messageDB, messageUrl, Replication.Direction.PULL);
//filter
pull.setFilter("message/by_username");
HashMap<String, Object> filterParams = new HashMap<>();
filterParams.put("username", usr);
pull.setFilterParams(filterParams);
pull.setContinuous(false); //oneshot
pull.start();
Apache设计文档:
Apache design document:
{
"_id": "_design/message",
"views": {
"by_username": {
"map": "function (doc) {\n emit([doc.username]);\n \n}"
}
},
"filters": {
"by_username": "function(doc, req){ if(!doc.username) return false; if(req.query.username && req.query.username != doc.username){return false} else {return true}}"
},
"language": "javascript"
}
使用块过滤器,同步将永远不会停止,但是数据库始终为空(3分钟后我没有找到任何文档)。
With the block filter, the synchronization will never stop but the database is always empty (I did not find any document after 3 minutes).
没有块过滤器,仅需几秒钟即可下载所有邮件。
谢谢。
Without the block filter, all messages are downloaded in only few seconds. Thanks.
推荐答案
但是,有一种解决方法可以使用带有ouchdb 2.x服务器的沙发床lite 1.4如上所述,无需对库进行任何更改。
请参考给出的答案此处
There is however a workaround for working with couchbase lite 1.4 with couchdb 2.x server to working without any change in the library as mentioned above. Please refer to answer given here
这篇关于Android-Couchbase Lite-带过滤器提取-Replication.setFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!