Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 38689 invoked from network); 22 Jan 2010 18:41:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jan 2010 18:41:37 -0000 Received: (qmail 93516 invoked by uid 500); 22 Jan 2010 18:41:35 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 93435 invoked by uid 500); 22 Jan 2010 18:41:35 -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 93425 invoked by uid 99); 22 Jan 2010 18:41:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 18:41:35 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jchris@gmail.com designates 209.85.160.56 as permitted sender) Received: from [209.85.160.56] (HELO mail-pw0-f56.google.com) (209.85.160.56) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 18:41:25 +0000 Received: by pwj16 with SMTP id 16so979882pwj.35 for ; Fri, 22 Jan 2010 10:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type:content-transfer-encoding; bh=bPOtMxNeDL6eveibYvZ1b/hJGVqZtn34mn/pesLat+U=; b=ExtM8VsJ5mnQj04pit7m0lpqlGP9VKWdZNPCCTl0A2eHFboxEeVDRdtxdsefNh4BIY B4LCjX//TeVQn0sffrtlmwvwXJvEQSY5w1HiP9jfJy/eKV0MA9H+4htVWKVTEVUNBrTP dMk6cpwc7tXaoGh0bHyc7nlxPYbD6hK1jExBg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=AoXS53kRVLjAhKyGXiIY5efr06IX8ZJNO6t80Q27G6tW7PF5BQzglRbHDnmf/JzqIF nZs22wGZTgOS+1e+C+QJlef1f6R/P/26YFF2+bVXIeO3YV/tL6yt5d2FUhYzykUEUpg8 6YmLefoHavmdACtHkPjjFRn7a1XhZQuKH6nxQ= MIME-Version: 1.0 Sender: jchris@gmail.com Received: by 10.142.66.34 with SMTP id o34mr1800389wfa.239.1264185663986; Fri, 22 Jan 2010 10:41:03 -0800 (PST) In-Reply-To: <255598.898.qm@web24818.mail.ird.yahoo.com> References: <255598.898.qm@web24818.mail.ird.yahoo.com> Date: Fri, 22 Jan 2010 10:41:03 -0800 X-Google-Sender-Auth: 9ceb3bd9aeb2e129 Message-ID: Subject: Re: view syntax for retrieving object without a field From: Chris Anderson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Fri, Jan 22, 2010 at 7:38 AM, Matt Villiers wrot= e: > I'm prototyping couchdb for a large application (for a possible migration= from an oracle system). > > I'l like to query my objects to get those _without_ a certain key. > My data: > {'id':'2','Type':'Article', country:'USA'} > {'id':'3','Type':'Article', country:'USA'} > {'id':'4','Type':'Article',} > {'id':'5','Type':'Article', country:null} > > I'd like to get the object number 4 (no field 'country'). > > I tried with this view: > > =A0 =A0 =A0 =A0 =A0 =A0function(doc) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if =A0(doc.Type =3D=3D "Article") { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emit('country' in doc, doc); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0} > function(doc) { if (doc.Type =3D=3D "Article") { if (doc.country) { emit(doc.country, null); } else { emit("--no-country", null); } } }; instead of "--no-country" you could emit false, but currently if there is no .country field then CouchDB will just skip the row. there are plans to make it so that attempts to emit undefined will be coerced to null (this is in keeping with the ecma5 standard) but that won't change things materially for you. Chris > With False as the request key but with no luck ... > > Is that feasible with couchdb ? Could you advise ? > > Best, > > Matt > > > > --=20 Chris Anderson http://jchrisa.net http://couch.io