Android - Couchbase lite - pull with filter - Replication.setFilter

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 12:58:50

问题


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 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 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"
}

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.


回答1:


Source : https://developer.couchbase.com/documentation/mobile/current/guides/couchbase-lite/native-api/replication/index.html#filtered-pull-from-couchdb-pouchdb-or-cloudant

Filtered pull from CouchDB, PouchDB or Cloudant

Since Couchbase Lite 1.2, filter functions in pull replications with non-Couchbase databases are no longer available. There is an incompatibility in the way the filter parameter is handled in the POST /{db}/_changes request (see #1139).




回答2:


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



来源:https://stackoverflow.com/questions/47220517/android-couchbase-lite-pull-with-filter-replication-setfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!