Counters like this won't work. Your map function *must* return the exact same output for identical inputs. Imagine you generate the view once. Then edit a document. When it goes back through the map view your function would give it a new counter. Assuming your documents are edited in a non-deterministic order you won't be able to rely on the counter to mean anything.
The only thing you could *almost* but not quite rely on it for would be to get the list of documents in the order of their last edit. And when I say almost, I mean it'll never work. But luckily there's _all_docs_by_seq which does exactly that. HTH, Paul On Tue, Nov 18, 2008 at 8:14 AM, Adam Groves <[EMAIL PROTECTED]> wrote: > 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 >> >