On Sat, Apr 4, 2009 at 2:15 AM, Nicolas Clairon <[email protected]> wrote: > To bad :-( This is a really standard feature. I hope it will be > integrate very soon in couchdb... > > For now, an easier solution would be to create a "doctype_count" document : > > { > id: "type1", > rev: "1-638393", > number: 1, > } > > And each time a document is created, we increment the "number" field. > A lot of conflict > will appear but I think it will be easy to deal with conflict than > keeping incremental in a > secondary database. Right ? >
No. That's a recipe for update conflicts. I think keeping a secondary database up to date will probably be easier, it's just a matter of doing the bookkeeping, like with any external indexer. You might end up having to run the "reduce" externally as well (on groups of map rows). This way you can keep track of which docs/revs contribute to each grouped key, and use that information to rerun the reduce incrementally. If you have few distinct types, you are probably better just using standard CouchDB reduce with group=true and sorting the full output by value. > On Fri, Apr 3, 2009 at 11:21 PM, Chris Anderson <[email protected]> wrote: >> On Fri, Apr 3, 2009 at 2:01 PM, Paul Davis <[email protected]> >> wrote: >>> Nope. There's nothing in CouchDB that allows for this yet. Different >>> methods have been discussed for adding it via things like a value >>> index to allow for users to selectively choose how things are sorted >>> in the output but noone's stepped up with an implementation yet. >>> >> >> I think the simplest path would be to "print" the results of a >> group=true or group_level query to a secondary database. Keeping it >> incremental is the challenge. >> >>> HTH, >>> Paul Davis >>> >>> On Fri, Apr 3, 2009 at 4:57 PM, Nicolas Clairon <[email protected]> wrote: >>>> Hi ! >>>> >>>> I'm getting through a sorting issue with couchdb. >>>> >>>> Let's say we have a classic map/reduce for counting the number of >>>> documents by type : >>>> >>>> function(doc){ >>>> emit(doc.doc_type, 1); >>>> } >>>> >>>> function(key, values){ >>>> return sum(values); >>>> } >>>> >>>> the results would be : >>>> >>>> type1 => 3 >>>> type2 => 1 >>>> type3 => 2 >>>> ... >>>> >>>> My question is simple : How can we sort the result by the compute reduce >>>> value ? >>>> We can sort by key, but can we sort by value ? >>>> >>>> Regards, >>>> >>>> Nicolas >>>> >>> >> >> >> >> -- >> Chris Anderson >> http://jchrisa.net >> http://couch.io >> > -- Chris Anderson http://jchrisa.net http://couch.io
