How to get total count in couchbase Views -
when query view in couchbase using user_id(key), limit(10) , skip(0) parameter, response has following structure:
{ "total_rows":1896, "rows":[...] }
here view return list of reports based on user_id:-
function map(doc, meta) { if (doc.type == 'report' && doc.subscribed) { (var subscriber in doc.subscribed) { emit(subscriber, doc); } } }
here sample report doc:-
{ "agree_allowed":true, "assigned_by":"", "assigned_to":"", "closed":[ ], "comments_allowed":true, "details":"test", "email":"", "status":"in progress", "subscribed":{ "user_cfd29b81f0263a380507":true, "user_cfd29b81f0263a380508":true, "user_cfd29b81f0263a380509":true, "user_cfd29b81f0263a3805010":true }, "summary":"test", "time_open":0, "timestamp":"2015-07-17t15:34:30.864z", "type":"report", "user_id":"user_cfd29b81f0263a380507", "username":"test17" }
but rows count 3, if want achieve pagination how can total count, can useful pagination.
total_rows
contains unfiltered count, should equal total number of subscribed
entries (all [user,report]
pairs).
if want efficient pagination, shouldn't use skip(n)
, because forces index scan n
first rows , discard them.
what should instead use startkey
, startkey_docid
, limit
(well, use skip(1)
rid of last result of previous page).
this explained in quite bit of detail in blog post: http://blog.couchbase.com/pagination-couchbase
Comments
Post a Comment