total_rows in view results and start/endkey usage
Hi all,
I got a minor problem with the result of a view when using start/end-key filtering.
The result is a json where the "total_rows" value is always the maximum number of documents the view could return, and not the "expected" number of the documents which match the given filter criteria.
Which gives me some headache when using a pagination.
My Workaround for now is using a view with a reduce function using only "_count" and using two queries:
- first with reduce=false and the limit/skip values for paging
- second with reduce=true
and then hacking the result set of the first query and changing the total_rows value to the result of the second query.
Which is a bad thing because there are two queries to Couchbase and the need to write to a (read-only) result set.
The two queries will look like similar to those:
- /assets/_design/title/_view/sorted_by_rank?skip=0&limit=25&startkey=["foo","bar"]&endkey=["foo","bar",[]]&reduce=false
- /assets/_design/title/_view/sorted_by_rank?startkey=["foo","bar"]&endkey=["foo","bar",[]]&reduce=true
Is there a way to get the number of matching document in the view result, that is regarding to startkey/endkey/keys but not limit/skip, w.g. in a key "matching_rows" or similar?
Best regards,
ARabus