Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 98433 invoked from network); 21 Jul 2010 21:21:18 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Jul 2010 21:21:18 -0000 Received: (qmail 80726 invoked by uid 500); 21 Jul 2010 21:21:17 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 80682 invoked by uid 500); 21 Jul 2010 21:21:16 -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 80674 invoked by uid 99); 21 Jul 2010 21:21:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jul 2010 21:21:16 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of frederick.bowen@gmail.com designates 209.85.214.52 as permitted sender) Received: from [209.85.214.52] (HELO mail-bw0-f52.google.com) (209.85.214.52) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jul 2010 21:21:08 +0000 Received: by bwz14 with SMTP id 14so901388bwz.11 for ; Wed, 21 Jul 2010 14:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=mdT8Vi0F086cNXd5WLjpC6Qkfw8gWcdMLDnXNZkR88g=; b=E0bvXlvCUlSTPVVbk11Lan0zpNqdKQRT24fRJAg06gzvuj8Y6KpKOw1u0l6OCIpcHm 3sF67ebDzqbkGAfqZOeFp/0QJDcoLcrk03r5ptvttz/Od2L9+MOsyP/ut444Jo01Nj2D APtHTXxfKE00UPCNT55A/pyDIveAK2keOinsE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=L35ePZBZxWe+TGBVbGhX3M3jwl0tiSK/AevntfYr78ja1Gqauz98/75INVFcTY3RY6 a20JoRfB4TTQWlA527XK1Vz3EfHjZ3LbswFEvZAKF/QOf23YZx42VSdy1/tXRzLq4Iy4 vodwj4z8Q5HbZjhAJbsUPv8ECKyaPLJ7Rcvuo= Received: by 10.204.19.83 with SMTP id z19mr629287bka.43.1279747247977; Wed, 21 Jul 2010 14:20:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.103.129 with HTTP; Wed, 21 Jul 2010 14:20:27 -0700 (PDT) In-Reply-To: References: From: Freddy Bowen Date: Wed, 21 Jul 2010 17:20:27 -0400 Message-ID: Subject: Re: a newbie question about querying an exact array field To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=00032555a3da1e3469048bec609f X-Virus-Checked: Checked by ClamAV on apache.org --00032555a3da1e3469048bec609f Content-Type: text/plain; charset=UTF-8 I don't quite understand your predicament. But take the doc: {"_id": "example1","my_array": [1,2,3,4,5]} To index your lists just make a view like: function(doc){ emit(doc.my_array, null); } Find your doc in a view: http://yourcouch/db/_design/dd/_view/ex?startkey=[1,2,3,4,5]&endkey=[1,2,3,4,5] Which returns: {"total_rows":1,"offset":0,"rows":[ {"id":"example1","key":[1,2,3,4,5],"value":null} ]} Beware that startkey=[1,2,3,4,5]&endkey=[1,2,3,4,5] matches everything that sorts in between. FB On Wed, Jul 21, 2010 at 4:33 PM, Richard Llewellyn wrote: > Thanks all for quick comments and heads up with javascript! I was under > the > dreamy impression that the array query value would be json encoded > automagically. > > I am storing values with simple keys but json lists and dicts and would > like > to index these values by exposing them in a view, not as their individual > elements (I find the many 'tag' examples) but in their entirety. > > >>You'll either have to json encode or hash the array and then compare > the hashes. > > Ok that makes sense, but how do I query with a json encoded value? I can > encode an array to json, and the arrays should be json already in the db, > but how would I write the query? > > How do I do what I mean below? Naively replacing my_array with a json > string eg "[1, 2, 3, 4, 5]" doesn't work. > > eg doc.array = [1,2,3,4,5] > > function(doc){ > if (doc.my_array == my_array in CLIENT ENCODED JSON) > { emit(doc.my_array, doc); > }} > > Thanks, > Rich > --00032555a3da1e3469048bec609f--