couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Groves" <>
Subject Pagination with Reduce Views
Date Wed, 12 Nov 2008 09:39:52 GMT

 I've been trying out couchdb for the past month or so now and I'm
still trying to get my head around some things which I would know how
to implement in SQL but am not sure how to implement in couch.

I've got a database with Project, Document and Version documents. Each
project has documents, each document has versions. I want to show an
overview of the documents and current version count per document in a
tabular form like so:

Document/Version Count

I've got this working using this map/reduce:

function(doc) {
  if(doc.type == "document") {
    emit([doc.project_id, doc._id], doc)
  if(doc.type == "version") {
   emit([doc.project_id, doc.document_id], 1)

function(keys,values) {
  var count = 0;
  var doc;
  for(var i = 0 ; i < values.length ; i++) {
    value = values[i];
    if(typeof(value)=="number") {
    } else {
      doc = value;
  doc.version_counter = count;

I'd like to paginate the results, so I checked out how that's done on
futon. Example params for "Next Page":
count = 10
descending = false
group = true
skip = 1
startkey = "335eee77a3bdefbf7fbf99a5f40cf687"
startkey_docid = 335eee77a3bdefbf7fbf99a5f40cf687

and the previous page is retrieved by setting descending to true and
using the previous startkey.

I can't however get descending = true to retrieve any data on my view.
I get {"rows":[]} no matter which start key I use. Does descending
true only work on views that aren't reduced?


Adam Groves

View raw message