4
votes

I'm looking to perform a query on my Couchbase database using the Java client SDK, which will return a list of results that include the document id for each result. Currently I'm using:

Statement stat = select("*").from(i("myBucket"))
                 .where(x(fieldIwantToGet).eq(s(valueIwantToGet)));

N1qlQueryResult result = bucket.query(stat);

However, N1qlQueryResult seems to only return a list of JsonObjects without any of the associated meta data. Looking at the documentation it seems like I want a method that returns a list of Document objects, but I can't see any bucket methods that I call that do the job.

Anyone know a way of doing this?

1

1 Answers

6
votes

You need to use the below query to get Document Id:

Statement stat = select("meta(myBucket).id").from(i("myBucket")) .where(x(fieldIwantToGet).eq(s(valueIwantToGet)));

The above would return you an array of Document Id.