Hi!,
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
DocumentA/1
DocumentB/4
DocumentC/2
I've got this working using this map/reduce:
Map
------
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)
}
}
Reduce
-----------
function(keys,values) {
var count = 0;
var doc;
for(var i = 0 ; i < values.length ; i++) {
value = values[i];
if(typeof(value)=="number") {
count+=value;
} else {
doc = value;
}
}
doc.version_counter = count;
return(doc);
}
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?
Cheers
Adam Groves