Search code examples
javacouchbasecouchbase-view

Couchbase View is empty


If I try to retrieve a list of documents from a Couchbase server via a view with the Java SDK I get an empty result list:

ViewResult result = dataManager.getBucket().query(ViewQuery.from("_design/dev_task", "byID"));
List<ViewRow> rows = result.allRows(); // rows is empty

However, in the web console the same view has a non-empty filtered result list. A retrieval by document ID, on the other hand, works flawlessly:

JsonDocument taskDocument = dataManager.getBucket().get("task1", JsonDocument.class);
// taskDocument contains the document for task1

The query was defined as:

function (doc, meta) {
  if (typeof(doc.taskID) == "number") {
    emit(doc.taskID, doc);
  }
}

and has the following name:

enter image description here

What might I be doing wrong?


Solution

  • Ok, I finally found the solution after reading this blog entry. The problem is the first parameter of the .from method: The _design/dev_ prefix must be avoided. So instead of calling

    ViewQuery.from("_design/dev_task", "byID")
    

    I have to use

    ViewQuery.from("task", "byID")
    

    This leaves me with a non-empty array of rows!