Using CouchDB , I have a document presenting an idea, you can evaluate this idea. Each idea is one document, and each rating is a different document. I do this in order to avoid concurrent access problems when people evaluate an idea.
My documents look like this (I simplified them):
Idea:
{ "_id": "idea1", "title": "A great idea" }
Rating:
{ "_id": "rating1", "rating": 1, "author": "author1" } { "_id": "rating2", "rating": 1, "author": "author2" }
I am currently using the reduction function to return me the idea ID and its rating (simple sum of ratings):
Map
function(doc) { if (doc.type == "rating") emit(doc.idea_id, doc.rating); }
Decrease:
function(keys, values, rereduce) { return sum(values); }
My question is: how could I "join" the document "idea" with the result of the reduction, which represents the rating for this idea?
source share