I understand that the reduce function is supposed to somewhat combine the results of the map function but what exactly is passed to the reduce function?
function(keys, values){
// what's in keys?
// what's in values?
}
I tried to explore this in the Futon temporary view builder but all I got were reduce_overflow_errors. So I can’t even print the keys or values arguments to try to understand what they look like.
Thanks for your help.
Edit:
My problem is the following. I’m using the temporary view builder of Futon.
I have a set of document representing text files (it’s for a script I want to use to make translation of documents easier).
text_file:
id // the id of the text file is its path on the file system
I also have some documents that represent text fragments appearing in the said files, and their position in each file.
text_fragment:
id
file_id // correspond to a text_file document
position
I’d like to get for each text_file, a list of the text fragments that appear in the said file.
Update
That’s the reason why there is
mapused instead ofemitit was renamed. Sorry I corrected my code to be valid in the recent version of CouchDB.Edit
I think what you are looking for is a has-many relationship or a join in sql db language. Here is a blog article by Christopher Lenz that describes exactly what your options are for this kind of scenario in CouchDB.
In the last part there is a technique described that you can use for the list you want.
You need a map function of the following format
Now you can query the view in the following way:
This gives you a list of the form
Old Answer
Directly from the CouchDB Wiki
Reduce functions are passed three arguments in the order key, values and rereduce
Reduce functions must handle two cases:
When rereduce is false:
i.e.
reduce([ [key1,id1], [key2,id2], [key3,id3] ], [value1,value2,value3], false)When rereduce is true:
i.e.
reduce(null, [intermediate1,intermediate2,intermediate3], true)Reduce functions should return a single value, suitable for both the value field of the final view and as a member of the values array passed to the reduce function.