Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 80916 invoked from network); 22 Jan 2010 21:10:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jan 2010 21:10:23 -0000 Received: (qmail 77403 invoked by uid 500); 22 Jan 2010 21:10:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 77332 invoked by uid 500); 22 Jan 2010 21:10:21 -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 77322 invoked by uid 99); 22 Jan 2010 21:10:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 21:10:21 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of awolff@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-px0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 21:10:15 +0000 Received: by pxi10 with SMTP id 10so1089835pxi.13 for ; Fri, 22 Jan 2010 13:09:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=kintDigz7DzZUbwLO4cR2DOlzhEctV/n+N0UTE2Bm6E=; b=Ck6JabRtDWw7Sqvysmh4TFsYF/9t6Qaigqn4E0zAXqP7Ox3OlObrw6gQdcqvvJ9mY7 hmxMMD9hJdf8CP/3Fuoo32MP6olM5euS4na8sThXUu+Oi6EKBhBJXb4vvWy89+swtI9c yiKwKx2AkUcjSSe3nJzw7NQldepAPi2gL5uBk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=x/SFqTZvf06RSfiMHgEENjSJnamfW/EMWQfOvb0qWXI/ht0P6NNf/T+N+ZUjc/Bxna dkCxW63SnwyZ3jSHIbzD0MEvRmkC0aav1Dho/dbFhNbB0KiCJJ48FlgG7vxB7YQLczI1 EodCW0ZVcatsa20JA9ieJ4d8WsgFuSRwtLnhA= MIME-Version: 1.0 Received: by 10.140.57.4 with SMTP id f4mr2396876rva.222.1264194594943; Fri, 22 Jan 2010 13:09:54 -0800 (PST) In-Reply-To: <54778.82.73.244.17.1264192694.squirrel@webmail.claranet.nl> References: <255598.898.qm@web24818.mail.ird.yahoo.com> <201001222013.44854.markus@buyways.nl> <54778.82.73.244.17.1264192694.squirrel@webmail.claranet.nl> Date: Fri, 22 Jan 2010 13:09:54 -0800 Message-ID: Subject: Re: view syntax for retrieving object without a field From: Adam Wolff To: user@couchdb.apache.org, markus@buyways.nl Content-Type: multipart/alternative; boundary=001636b2b01fc235ac047dc73dcb --001636b2b01fc235ac047dc73dcb Content-Type: text/plain; charset=ISO-8859-1 In your first example, you wrote if (doc.field == "undefined") I think you meant if (typeof doc.field == "undefined") But I usually write if (doc.field === void 0) if I really want to check for undefined, since "undefined" is not a js keyword; it's just a conventional variable that has no value. A On Fri, Jan 22, 2010 at 12:38 PM, Markus Jelsma wrote: > Hello, > > > For the sake of clarity and reusability i have added this problem to the > wiki [1]. Please check and modify or extend if there are some flaws or if > something is missing. > > [1]: > http://wiki.apache.org/couchdb/View_Snippets#documents_without_a_field > > > Cheers, > > > Markus Jelsma said: > > Hi, > > > > > > I have some documents, all with a `name` field and some with a country > > field defined. Using the map function below i can retrieve all > > documents that have no country field defined. > > > > function (doc) > > { > > var > > > > if (doc.country == "undefined") > > { > > emit(doc.name, null); > > } > > } > > > > I do believe this could be very unusable in many situations, especially > > if you need to retrieve documents based on the absence of a lot of > > different fields. > > > > 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); > > } > > } > > } > > > > Now you can just query the view with your key and retrieve all documents > > without that field. > > > > Hope this helps. > > > > > > Cheers, > > > > --001636b2b01fc235ac047dc73dcb--