yeah but then my counter is still tied to the age of the document. Say I'd like to return a list of documents sorted by name.
I'd have a view like this: count = 0; function(doc) { if(doc.type == "document") { count = count + 1 emit(doc.name, count); } } I then create 4 documents in this order: Doc2, Doc3, Doc1, Doc4. The above view would give me the following results: Key Value ------------------- Doc1 2 Doc2 4 Doc3 3 Doc4 1 Which is not what I'm after. 2008/11/18 Ulises <[EMAIL PROTECTED]>: > That's what I thought. The output is definitely sorted by key, but the >> document with a 'count' of one is in the middle of my results. >> >> I just tried this view for debugging: >> >> count = 0; >> function(doc) { >> if(doc.type == "document") { >> count = count + 1 >> emit(doc._id, [count, doc.updated_at]); >> } >> } >> >> and it turns out that the document with a count of 1 is the most >> recently updated document. >> > > But isn't the signature of the emit fn emit(key, value)? Wouldn't it make > more sense then to emit([doc._id, count], some_value) however even then it'd > end up sorted only by doc._id. Perhaps emit([count, doc._id], some_value) > would do the trick. > > U >