Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 38AE6953A for ; Fri, 13 Jan 2012 11:30:33 +0000 (UTC) Received: (qmail 78974 invoked by uid 500); 13 Jan 2012 11:30:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 78619 invoked by uid 500); 13 Jan 2012 11:30:26 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 78579 invoked by uid 99); 13 Jan 2012 11:30:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jan 2012 11:30:22 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of marcello.nuccio@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-qy0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jan 2012 11:30:16 +0000 Received: by qcsp15 with SMTP id p15so204332qcs.11 for ; Fri, 13 Jan 2012 03:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5hTKOc5FwlQrxLelMvJZg+bxgT39kwKo5s7XQR4qm1I=; b=QUncXkTo3gdBeBfh17ghkwKqFcnCMuquIzY1TaANWDMAaFtOHraVgB85aK8k2SISB4 8lCojloWrJl/fe4fx50FPNhYqs+CW/4ifDuyfRFOnjpS7HGLsytvBWwbb0G/2r4If8pT craufwkO6GWAfVucnwKir3jceLunfr9tsaGoQ= MIME-Version: 1.0 Received: by 10.224.174.71 with SMTP id s7mr830234qaz.4.1326454195578; Fri, 13 Jan 2012 03:29:55 -0800 (PST) Received: by 10.229.166.14 with HTTP; Fri, 13 Jan 2012 03:29:55 -0800 (PST) In-Reply-To: References: Date: Fri, 13 Jan 2012 12:29:55 +0100 Message-ID: Subject: Re: Lookup views From: Marcello Nuccio To: user@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org 2012/1/13 : [...] > 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