Not able to get all rows returned from Couchbase View

ViewResult.allRows() is not returning all result from View, it is only returning a subset of result set.

ViewResult.totalRows() returns 70 but ViewResult.allRows().size() = 2 and below mentioned code itrates 2 time only

  for (ViewRow row : viewResult) {
Note: I am using java-client v 2.1.4


the allRows() method is the same as rows(), it just batches them up in a list instead of giving you an iterator the totalRows() count is an information from the server how many rows are stored in your view. You are likely querying with a param that filters them down from 70 to 2.

Hi @vinod,
Here is the part of the Java SDK documentation that shows how to iterate over a view result set:

ViewResult result = bucket.query(ViewQuery.from("beers_and_breweries", "by_name"));

Iterator<ViewRow> rowIterator = result.rows();   
while (rowIterator.hasNext()) {
ViewRow row =;
JsonDocument doc = row.document();

if (doc.content().getString("type").equals("beer")) {

I hope this helps.

Thanks Martin for Help… I have tried your solution in my application but it’s not working, It is only returning a subset of records for me it’s 66 rows but in database I have more that 1000 records if I don’t provide ‘keys’. But If I provide ‘keys’ it’s only returning 66 records.

Do I have to configure view to return all rows at server side?

Thanks Daschl for reply to my post.

In database I have more than 1000 records are there, if I am not providing any filter it’s returning 66 rows and if I provide filter it is only returning 2 records.

If I run the view on Couchbase Console, it is showing me all records.

Do I need to configure some thing to pull all rows from a view?

did you make sure to publish the view and then access the published one from both SDK and UI? Development views can vary greatly in the data they return, only a published view will give you the right output on your complete dataset.


@daschl, When I am running view from console with ‘full_set=true’ , it’s giving all rows. But I am not able to pass this option from Java Client SDK…

I need some workaround to pass this value.

as noted in the other forum post, it seems you are running on development views. Publish your view into production, then the data set will be accurately returned.

@daschl, Thanks for solution, now I am able to get full set data after publishing view to ‘Production’.

Here I am facing another issue, now I am not able to filter data based on ‘keys’.


If I use mentioned URL with ‘keys’, it’s returning


If I remove ‘keys’ attribute it’s giving me all records in row section.

NOTE: I copied above mentioned URL from *couchdb.log*

ViewQuery.from(documentDesignName, viewName).keys(JsonArray.fromJson(keysJson)).stale(Stale.FALSE)

You can use it in this way.

@shiv4nsh, I am using below mentioned code to create ViewQuery…

 String[] params -- keys values which I am passing to view to filter result set.. 
    JsonArray jsonArray = JsonArray.create();
    for (String param : params) {
    ViewQuery query = ViewQuery.from(design, view);

But it is not working… Do I need to pass some encoding parameter or set some configuration parameter?

What is the error that you are getting.?

@vinod how do the keys look like you are emitting and how does the view query generated look like? You can run toString() on it to see the http query URI and compare them.

@shiv4nsh, I am not getting any error, it’s not returning any rows.


toString() is not returning ‘keys’ value.

ViewQuery.toString() : stale=false&inclusive_end=false   

URL captured from ‘couchdb.log


Note: If paste above mentioned URL in browser a " symbol will comes automatically.

Am I missing anything here?


I meant after that toString on “query”, so that you can see what is actually written to the keys() method!

@daschl, I am calling toString() on VIewQuery object. In toString() implementation it is not adding ‘keys’ value.

LOGGER.debug("$$ Query == " + query.toString());

@vinod maybe your params array is just empty?

@daschl & @shiv4nsh … I have found the problem, in query I was setting in inclusive_end=false, if I make it inclusive_end=true, it’ working.

Thanks a lot for the time you guys put to help me out…


Super glad you found it!