0

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?

Bastian
  • 4,638
  • 6
  • 36
  • 55

2 Answers2

1

Have you published the view? I'm going to guess that the SDK is running in production mode, so document retrieval will work as the document exists but for views it won't be looking in the development views as your screenshot above shows.

scalabilitysolved
  • 2,473
  • 1
  • 26
  • 31
  • The view has not been published, yet. How can I see which mode the SDK is running in? I tried to set an enviroment variable with `System.setProperty("viewmode", "development");`. This, however, did not change anything. – Bastian Apr 08 '15 at 13:27
  • Usually it defaults to production mode if I remember correctly, you can see in startup logs the SDK will log out which mode it is in. I'd just publish the view and see if that makes it work, if it does then problem solved and if not at least we can look at something else as the problem. – scalabilitysolved Apr 08 '15 at 14:58
  • The console does not mention any mode. So I just published the view and did not notice any behavioural change; `rows` remains empty. Do you have any other ideas? – Bastian Apr 10 '15 at 08:59
0

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!

Bastian
  • 4,638
  • 6
  • 36
  • 55
  • those two lines are exactly the same – Dan Levin Nov 03 '15 at 14:04
  • @DanLevin Thank you for this comment. I fixed the second line. – Bastian Nov 03 '15 at 14:57
  • np, unfortunately i still get view not found error :( any ideas? – Dan Levin Nov 03 '15 at 16:22
  • Hmmm... currently, I am not actively involved in Couchbase any more. So, my knowledge is already "rusting away". Have you tried scalabilityinvolved's answer? You could also just post your own issues in a new post to get input from more experienced users. – Bastian Nov 04 '15 at 08:19
  • Make sure you are querying the production view (which is the published dev view). Also, make sure when you are using the good names: the dev view usually has a dev_ prefix and the production view a design_ prefix. You can query the production view without using any prefix. – Ana Jan 30 '17 at 09:22