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:

http://vmdev-memcache1.connectfirst.com:8092/default/_design/dialrequests/_view/expired_by_server?inclusive_end=true&reduce=false&stale=false&connection_timeout=60000&start_key=[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");
        vq.startKey("[1001,0,0,0,0,0,0]");
        vq.endKey("[1001,9999,99,99,99,99,99]");
        vq.inclusiveEnd(true);
        vq.reduce(false);
        vq.stale(Stale.FALSE);

        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:

{“id”:“201411050947019990000000000001”,“key”:[1001,2013,11,5,14,47,1],“value”:null},
{“id”:“201411050947019990000000000005”,“key”:[1001,2013,11,5,14,47,1],“value”:null},

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))
        .inclusiveEnd()
        .reduce(false)
        .stale(Stale.FALSE);

    // wrongly quoted
    ViewQuery q2 = ViewQuery
        .from("dialrequests", "expired_by_server")
        .startKey("[1001, 0, 0, 0, 0, 0, 0]")
        .endKey("[1001,9999,99,99,99,99,99]")
        .inclusiveEnd()
        .reduce(false)
        .stale(Stale.FALSE);

    System.out.println(q1);
    System.out.println(q2);

Which prints

reduce=false&stale=false&inclusive_end=true&startkey=%5B1001%2C0%2C0%2C0%2C0%2C0%2C0%5D&endkey=%5B1001%2C9999%2C99%2C99%2C99%2C99%2C99%5D
reduce=false&stale=false&inclusive_end=true&startkey=%22%5B1001%2C+0%2C+0%2C+0%2C+0%2C+0%2C+0%5D%22&endkey=%22%5B1001%2C9999%2C99%2C99%2C99%2C99%2C99%5D%22

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

Thanks. That was it!