Inconsistency Between Console and JDK

I have an issue where the console (Couchbase 3.0.1) and the JDK (2.0.1) are behaving differently.

This URI returns what I would expect:[1001,0,0,0,0,0,0]&end_key=[1001,9999,99,99,99,99,991]

This snippet of java code does not, even thought it should be identical:

ViewQuery vq = ViewQuery.from("dialrequests","expired_by_server");

        ViewResult vr = bucket.query(vq);

The Java code returns 0 records, while the URL returns the correct amount. Here is a snippet of what the data looks like:


Thanks in advance.

I don’t immediately spot any reason. As a debugging step, you may want to turn the log level up to the max and then you’ll be able to see the URLs.

I probably know what’s going on. When you construct a query from the SDK, its very important you get the output JSON right. So here you are inserting a string, which will make it quoted automatically. Both start and endkey also take a JsonArray which should make it similar to your query from the UI.

look at this:

    // what you want
    ViewQuery q1 = ViewQuery
        .from("dialrequests", "expired_by_server")
        .startKey(JsonArray.from(1001, 0, 0, 0, 0, 0, 0))
        .endKey(JsonArray.from(1001, 9999, 99, 99, 99, 99, 99))

    // wrongly quoted
    ViewQuery q2 = ViewQuery
        .from("dialrequests", "expired_by_server")
        .startKey("[1001, 0, 0, 0, 0, 0, 0]")


Which prints


(note the %22 in the start and endkeys to wrongly quote)

Thanks. That was it!