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