2012/1/13 <[email protected]>: [...] > Unfortunately, sometimes the enrichment changes. For example each trade has > a fruit field and we have a mapping from fruit to fruit type. Today apples, > oranges and pears are classified as round fruit whereas bananas are long > fruit so we can put a fruit type field on the document as we load it in but > tomorrow that classification might change and pears might become lumpy fruit > instead of round fruit. We could go back and update every pear trade in the > database but we'd rather not have fruit type on the document at all and > maintain a separate mapping "table". > > We thought that perhaps the map function could reference another database > that was keyed on fruit and had documents containing the fruit type but > don't seem to be able to perform this lookup in the mapping. We could get > the document itself on the result but not extract just one field to augment > the original documents. We also considered generating the view's design > dynamically out of a mapping table and replicating the mapping into explicit > logic in the javascript but this seemed like an abuse.
If update of all documents is not an option for you, the easiest solution that I see is hinted in your last phrase: "We also considered generating the view's design dynamically out of a mapping table and replicating the mapping into explicit logic in the javascript but this seemed like an abuse." In map functions, you can load CommonJS[1] modules. You can put the mapping table in a module, and update only that module when the data changes. [1]: http://wiki.apache.org/couchdb/CommonJS_Modules HTH, Marcello
