From user-return-7342-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Thu Nov 05 07:46:48 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 76787 invoked from network); 5 Nov 2009 07:46:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Nov 2009 07:46:47 -0000 Received: (qmail 7731 invoked by uid 500); 5 Nov 2009 07:46:46 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7647 invoked by uid 500); 5 Nov 2009 07:46:46 -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 7637 invoked by uid 99); 5 Nov 2009 07:46:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 07:46:46 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of b.candler@pobox.com designates 64.74.157.62 as permitted sender) Received: from [64.74.157.62] (HELO sasl.smtp.pobox.com) (64.74.157.62) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 07:46:44 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 118B0939CF; Thu, 5 Nov 2009 02:46:21 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:message-id:references:mime-version:content-type :in-reply-to; s=sasl; bh=y4yM5N3o09pPvQateqzbOh8p9xU=; b=C7blmgV 2A1kyaQEmOmz44WRX+TwWov9Z8S+bA9ZzZ/gBl6o9KoZ+AyL6PwCgoJRtfCfEijd mNu8oew4bgE0FNiWE0Od3dk0L/oH7jvbNAN3YiwywB9grx4prZHIUE289g5XlSZO ketyLcKGsuN5Y35oVANYe0T0am0dlhm9L4zk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=date:from:to:cc :subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=sasl; b=Wii2dwdGKfyj1Q5a9/yOBM5lX5JjunzJ1 or3i+izbEXOuotkc0mmkwPBpOfUobwosFtPC8DyV7bs/NbqACCa2PwXz/WIgCtCV GMosWXDj0vHz1FGjw6TjRTcD6wi9u35MTvMq8PjtvxY1NaavmSskdXYxhigL0ol/ 8EhlAVQNTo= Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 0178A939CE; Thu, 5 Nov 2009 02:46:19 -0500 (EST) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 6CA49939CD; Thu, 5 Nov 2009 02:46:18 -0500 (EST) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1N5x2u-0001l6-MR; Thu, 05 Nov 2009 07:46:16 +0000 Date: Thu, 5 Nov 2009 07:46:16 +0000 From: Brian Candler To: Adam Kocoloski Cc: user@couchdb.apache.org Subject: Re: mapping on non existing fields Message-ID: <20091105074616.GA6654@uk.tiscali.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: 4E80C406-C9DF-11DE-B74B-A67CBBB5EC2E-28021239!a-pb-sasl-sd.pobox.com On Wed, Nov 04, 2009 at 01:59:43PM -0500, Adam Kocoloski wrote: >> Im new to couchDB and im curious what couchDB behaves when I try to >> MAPPING >> non-existing fields. >> >> For example: >> >> Document 1 has field1, field2, field3 >> Document 2 has field1, fied4, field5 >> >> function1 (doc) { >> emit (doc.field1, doc.field4); >> } >> >> function2 (doc) { >> emit (doc.field6, doc.field7); >> } >> >> What are the results from function 1 and function 2 ? >> >> Thanks. > > function2 will throw an exception in the view server. It's not fatal, > but it's expensive, so not a good idea. You should check for the > presence of the field first. A convenient shorthand for this is: function2(doc) { emit(doc.field6 || null, doc.field7 || null); } or to avoid emitting the key if field6 is not present, function2(doc) { if (doc.field6) { emit(doc.field6, doc.field7 || null); } }