Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Java client 1.1-dp not returning documents when querying views

3 replies [Last post]
  • Login or register to post comments
Mon, 08/20/2012 - 17:35
Tim Pedersen
Offline
Joined: 08/16/2012
Groups: None

Hi all,

I'm using the Java 1.1-dp client to do queries against views. Setting query.setIncludeDocs(true) doesn't actually result in the query ViewResponse having documents (ViewRow.getDocument() returns null).

Digging into the code, it looks like that the Query class doesn't actually set the "include_docs" parameter, nor does DocsOperationImpl.parseResult try to extract the "doc" element from the returned JSON.

Is this deliberate? Or am I missing something? I'd really prefer not having to make a separate call to get the docs while iterating through a ViewResponse.

Cheers,

Tim Pedersen

__________________

Tim Pedersen

Top
  • Login or register to post comments
Mon, 08/20/2012 - 19:23
ingenthr
Offline
Joined: 03/16/2010
Groups:

It is deliberate. We've done a logical "include docs" rather than a physical HTTP query for it. When you set setIncludeDocs(true) as long as the view rows have document IDs associated with them, you can fetch the doc from the results. In background, the client will retrieve the documents asynchronously such that they're ready when your code gets there.

Top
  • Login or register to post comments
Mon, 08/20/2012 - 19:47
Tim Pedersen
Offline
Joined: 08/16/2012
Groups: None

Hmm, I must be missing something then - how do I get the docs asynchronously? This is my code (couchbaseTemplate is just a Spring bean that wraps a pool of clients, and handles async gets and sets):

@Test
public void testViews() throws Exception {
CouchbaseClient client = couchbaseTemplate.getClientPool().borrowObject();

try {
View view = client.getView("person", "links");
Query query = new Query();
query.setRange("[\"person:12346\",0]", "[\"person:12346\",999]");
query.setIncludeDocs(true);

ViewResponse viewResponse = client.query(view, query);
for(ViewRow viewRow:viewResponse){
String id = viewRow.getId(); // id ok
String key = viewRow.getKey(); // key ok
String value = viewRow.getValue(); // value ok - although I in this case I don't emit a value in view
String doc = (String) viewRow.getDocument(); // returns null - should return something :(
log.debug(doc);

}

} catch (Exception e) {
throw(e);
} finally {
couchbaseTemplate.getClientPool().returnObject(client);
}
}

/TP

__________________

Tim Pedersen

Top
  • Login or register to post comments
Mon, 08/20/2012 - 19:54
Tim Pedersen
Offline
Joined: 08/16/2012
Groups: None

I just realised that the problem isn't with the query/view code but is because of an issue when using CouchbaseConnectionFactoryBuilder.
With 1.1-dp, if I set up a client like so:

URI base = new URI(String.format("http://%s:8091/pools", server));
List baseURIs = new ArrayList();
baseURIs.add(base);
CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
cfb.setOpTimeout(10000);
cfb.setOpQueueMaxBlockTime(10000);
CouchbaseConnectionFactory cf = cfb.buildCouchbaseConnection(baseURIs, bucket, "", "");
CouchbaseClient client = new CouchbaseClient(cf);

getFuture = client.asyncGet(key);
value = (String) getFuture.get(); // value is not null and contains the document for the key

client.get() and viewRow.getDocument() return null values.

If I just use CouchbaseConnectionFactory:

URI base = new URI(String.format("http://%s:8091/pools", server));
List baseURIs = new ArrayList();
baseURIs.add(base);
CouchbaseConnectionFactory cf = new CouchbaseConnectionFactory(baseURIs, bucket, "");
CouchbaseClient client = new CouchbaseClient(cf);

getFuture = client.asyncGet(key);
value = (String) getFuture.get(); // value is not null and contains the document for the key

client.get() and viewRow.getDocument() return the correct values.

I've raised a Jira for this: http://www.couchbase.com/issues/browse/JCBC-102

/TP

__________________

Tim Pedersen

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker