Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 82048 invoked from network); 25 Jan 2010 16:51:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Jan 2010 16:51:39 -0000 Received: (qmail 98987 invoked by uid 500); 25 Jan 2010 16:51:38 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 98939 invoked by uid 500); 25 Jan 2010 16:51:38 -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 98929 invoked by uid 99); 25 Jan 2010 16:51:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jan 2010 16:51:38 +0000 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [91.189.90.139] (HELO adelie.canonical.com) (91.189.90.139) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jan 2010 16:51:28 +0000 Received: from hutte.canonical.com ([91.189.90.181]) by adelie.canonical.com with esmtp (Exim 4.69 #1 (Debian)) id 1NZS9b-0002lM-Fk for ; Mon, 25 Jan 2010 16:51:07 +0000 Received: from c-68-34-42-190.hsd1.md.comcast.net ([68.34.42.190] helo=[192.168.1.2]) by hutte.canonical.com with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NZS9b-0000if-Ad for user@couchdb.apache.org; Mon, 25 Jan 2010 16:51:07 +0000 Message-ID: <4B5DCBF9.8040807@canonical.com> Date: Mon, 25 Jan 2010 11:51:05 -0500 From: eric casteleijn User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8pre) Gecko/20100124 Shredder/3.0.2pre MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: view syntax for retrieving object without a field References: <255598.898.qm@web24818.mail.ird.yahoo.com> <201001222013.44854.markus@buyways.nl> In-Reply-To: <201001222013.44854.markus@buyways.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org > Let's provide you with a better alternative, you need only one view to handle > all possible negations, you only need to specify on which negations you want > to select, check it out! > > function (doc) > { > var fields = new Array("name", "country"); > > for (idx in fields) > { > if (typeof eval("doc." + fields[idx]) == "undefined") > { > emit(fields[idx], null); > } > } > } > I think it's perfectly safe in this case, but in general I would not encourage the use of eval, as it might trip up inexperienced developers into creating serious security issues in their applications. Almost always you can solve the problem without eval, as I think is the case here, at the expense of a little more code. Unfortunately the proof is too large to fit in the margin. ;)