The brewery_beers view outputs a composite
list of breweries and beers they brew by using the view output
format to create a 'fake' join, as detailed in
Section 9.9.10, “Solutions for Simulating Joins”. This
outputs the brewery ID for brewery document types, and the
brewery ID and beer ID for beer document types:
function(doc, meta) { switch(doc.type) { case "brewery": emit([meta.id]); break; case "beer": if (doc.brewery_id) { emit([doc.brewery_id, meta.id]); } break; } }
The raw JSON output from the view:
{ "total_rows" : 7315, "rows" : [ { "value" : null, "id" : "110f0013c9", "key" : [ "110f0013c9" ] }, { "value" : null, "id" : "110fdd305e", "key" : [ "110f0013c9", "110fdd305e" ] }, { "value" : null, "id" : "110fdd3d0b", "key" : [ "110f0013c9", "110fdd3d0b" ] }, … { "value" : null, "id" : "110fdd56ff", "key" : [ "110f0013c9", "110fdd56ff" ] }, { "value" : null, "id" : "110fe0aaa7", "key" : [ "110f0013c9", "110fe0aaa7" ] }, { "value" : null, "id" : "110f001bbe", "key" : [ "110f001bbe" ] } ] }
The output could be combined with the corresponding brewery and beer data to provide a list of the beers at each brewery.