Not able to get all rows returned from Couchbase View

connections

#1

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) {
      System.out.println(row);
  }
Note: I am using java-client v 2.1.4
  <dependency>
  	<groupId>com.couchbase.client</groupId>
  	<artifactId>java-client</artifactId>
  	<version>2.1.4</version>
  </dependency>

Cannot seem to access "Full Set" of a Development View
#2

@vinod

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.


#3

Hi @vinod,
Here is the part of the Java SDK documentation that shows how to iterate over a view result set:
http://docs.couchbase.com/developer/java-2.0/java-intro.html

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

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

if (doc.content().getString("type").equals("beer")) {
    System.out.println(doc.content().getString("name"));
}
}

I hope this helps.


#4

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?


#5

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?


#6

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.


#7

@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.


#8

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.


#9

@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’.

/default/_design/couchbase_service/_view/getUtilizationBasedOnPractice?stale=false&inclusive_end=false&keys=%5B%22DAS%22%5D

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

{“total_rows”:73342,“rows”:[
]
}

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

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

#10

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

You can use it in this way.


#11

@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) {
        jsonArray.add(param);
    }
    ViewQuery query = ViewQuery.from(design, view);
    query.inclusiveEnd(false);
    query.stale(Stale.FALSE);
    query.keys(jsonArray); 

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


#12

What is the error that you are getting.?


#13

@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.


#14

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


#15

@daschl,

toString() is not returning ‘keys’ value.

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

URL captured from ‘couchdb.log

/default/_design/couchbase_service/_view/getUtilizationBasedOnPractice?stale=false&inclusive_end=false&keys=%5B%22DAS%22%5D

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

Am I missing anything here?


#16

@vinod

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


#17

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

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

#18

@vinod maybe your params array is just empty?


#19

@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…


#20

Super glad you found it!