ChriX
ChriX

Reputation: 961

First query with Couchbase Java Client returns no rows

Today, I downloaded the last version of Couchbase CE and the JDK client and I tried this simple code (it's Groovy code) on the beer sample bucket:

package couchbase.beer

import com.couchbase.client.java.Cluster
import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.query.N1qlQuery
import com.couchbase.client.java.view.ViewQuery
import static com.couchbase.client.java.query.Select.select
import static com.couchbase.client.java.query.dsl.Expression.i

def cluster = CouchbaseCluster.create()

def beerBucket = cluster.openBucket('beer-sample')


def oneBeer = beerBucket.get('21st_amendment_brewery_cafe')
assert oneBeer
println oneBeer

println "==================> HERE  <=================="


def result = beerBucket
        .query(N1qlQuery.simple(select("*").from(i('beer-sample')).limit(10)))

println "SIZE: ${result.rows().size()}"

cluster.disconnect()

The first query by key works well. I retrieve a JSON object. But when I code the N1QL query, I've no result. For information, the code above comes from the couchbase developer site.

Upvotes: 2

Views: 254

Answers (1)

subhashni
subhashni

Reputation: 216

Using the java client, you can check if the query succeeded using result.finalSuccess() and also get the actual error info using result.errors() api reference is here. On a side note in case you hadn't known before, beer-sample bucket does not load with indexes by default. For using n1ql queries, you must set up index.

Upvotes: 5

Related Questions