incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject Re: Ordering by values calculated by a map/reduce
Date Mon, 01 Dec 2008 19:40:49 GMT
Something like Antony's external handler could be generalized to keep
an up to date version of the full results from a group=true reduce
query, stored in a secondary database. There are some old threads on
the topic, although I'm having trouble bringing them up just now.
(Googled "remap")

Anyway, by keeping group reduce results (each row to its own document)
in another db, you could define a view that ordered them by value.

This functionality would be generally useful and could be implemented
as an _external, or as regular script triggered by cron.


On Sun, Nov 30, 2008 at 11:39 PM, Ben Bangert <> wrote:
> I want to solve what I thought was a fairly simple problem, though
> unfortunately it seems to be rather tricky. I asked on the IRC channel, and
> got some good input, but neither really seemed like a very good solution.
> The problem:
> I want to allow users to rate things. They do this very very frequently, so
> I can't store it in the actual document being rated, so I have Rating
> documents. It's easy enough to write a map/reduce that gives me the computed
> average rating for a given document, however, it seems to be impossible to
> get a listing of the highest rated documents, as I can only get the computed
> rating for a document one at a time.
> The possible solutions:
> - Buffer rating additions, then at a later time, run through them and
> calculate the new average rating, store it in the document as
> computed_rating, so I can order on that in the key
> - Cron a job that goes in and looks for new rating every 5 mins or whatever,
> and then does the same as the previous solution by storing it in a
> computed_rating field
> I'm not a fan of either of these, because #1 means if my webapp hiccups, I
> lose ratings, and #2 is just a pain to keep sweeping the db for new Rating
> documents then going through updating all the documents.
> Is there really no other solutions that don't require me to store the
> computed rating in the doc itself? There's no way I can perhaps order on the
> value from the map/reduce, rather than only being able to order on the key?
> Thanks,
> Ben

Chris Anderson

View raw message