Cloudant同步android过滤拉

时间:2017-03-13 04:02:52

标签: android cloudant

我的数据库有很多文档,每个文档都有一个名为doc_type的字段,所以我可以过滤它,但android在尝试过滤时出错:

Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("doc_type", "doc_company");
        PullFilter filter = new PullFilter("company/list", parameters);
        Replicator replicator = ReplicatorBuilder.pull()
                .from(uri).to(ds)
                .filter(filter)
                .build();

错误:

       CouchException: error: Unknown error, reason: Unknown reason, statusCode: 404, msg: Object Not Found, cause: java.io.FileNotFoundException: https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000
 at com.cloudant.sync.internal.mazha.CouchClient$ExecuteResult.<init>(CouchClient.java:112)
 at com.cloudant.sync.internal.mazha.CouchClient$ExecuteResult.<init>(CouchClient.java:85)
 at com.cloudant.sync.internal.mazha.CouchClient.execute(CouchClient.java:188)
 at com.cloudant.sync.internal.mazha.CouchClient.access$100(CouchClient.java:54)
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:245)
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:242)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:209)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:242)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:227)
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:301)
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:295)
 at com.cloudant.sync.internal.replication.CouchClientWrapper.changes(CouchClientWrapper.java:125)
 at com.cloudant.sync.internal.replication.PullStrategy.nextBatch(PullStrategy.java:451)
 at com.cloudant.sync.internal.replication.PullStrategy.replicate(PullStrategy.java:235)
 at com.cloudant.sync.internal.replication.PullStrategy.run(PullStrategy.java:177)
 at java.lang.Thread.run(Thread.java:761)
                Caused by: java.io.FileNotFoundException: https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000
 at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
 at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
 at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
 at com.cloudant.http.HttpConnection.responseAsInputStream(HttpConnection.java:420)
 at com.cloudant.sync.internal.mazha.CouchClient.execute(CouchClient.java:171)
 at com.cloudant.sync.internal.mazha.CouchClient.access$100(CouchClient.java:54) 
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:245) 
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:242) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:209) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:242) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:227) 
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:301) 
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:295) 
 at com.cloudant.sync.internal.replication.CouchClientWrapper.changes(CouchClientWrapper.java:125) 
 at com.cloudant.sync.internal.replication.PullStrategy.nextBatch(PullStrategy.java:451) 
 at com.cloudant.sync.internal.replication.PullStrategy.replicate(PullStrategy.java:235) 
 at com.cloudant.sync.internal.replication.PullStrategy.run(PullStrategy.java:177) 
 at java.lang.Thread.run(Thread.java:761) 

我有带过滤功能的文件:

{
  "_id": "_design/company",
  "_rev": "15-49d2081b2e3c35ae833617fd2356e6d3",
  "views": {
    "list": {
      "map": "function (doc) {\n  emit(doc);\n}"
    },
    "filter": {
      "map": "function (doc, req) {\n  emit(doc._id, 1);\n}"
    }
  },
  "language": "javascript"
}

当我访问

  

https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000

它给了我这条消息:

{"error":"not_found","reason":"missing json key: filters"}

怎么了?我完全按照文件说https://github.com/cloudant/sync-android/blob/master/doc/replication.md(最后)

1 个答案:

答案 0 :(得分:0)

我找到了 - &gt; groups.google.com/forum/#!topic/mobile-couchbase/tw5462qMFeM

我从cloudant数据库(在线)中删除了_replicator文档并开始工作