Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 38415 invoked from network); 15 Sep 2010 21:25:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Sep 2010 21:25:32 -0000 Received: (qmail 12048 invoked by uid 500); 15 Sep 2010 21:25:31 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 11869 invoked by uid 500); 15 Sep 2010 21:25:30 -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 11861 invoked by uid 99); 15 Sep 2010 21:25:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Sep 2010 21:25:30 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [74.125.82.54] (HELO mail-ww0-f54.google.com) (74.125.82.54) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Sep 2010 21:25:22 +0000 Received: by wwb22 with SMTP id 22so262987wwb.23 for ; Wed, 15 Sep 2010 14:25:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.156.202 with SMTP id y10mr1922754wbw.48.1284585517285; Wed, 15 Sep 2010 14:18:37 -0700 (PDT) Received: by 10.227.135.196 with HTTP; Wed, 15 Sep 2010 14:18:37 -0700 (PDT) In-Reply-To: <4C91364A.1040608@gmail.com> References: <4C91364A.1040608@gmail.com> Date: Wed, 15 Sep 2010 14:18:37 -0700 Message-ID: Subject: Re: One-sided 1-to-many relationship From: Kenneth Tyler To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=0016363b9a587100f5049052df08 X-Virus-Checked: Checked by ClamAV on apache.org --0016363b9a587100f5049052df08 Content-Type: text/plain; charset=ISO-8859-1 I think this is the feature you want to use. from the wiki: Linked documents *This is a new feature in couchdb 0.11* If you emit an object value which has *{'_id': XXX}* then include_docs will fetch the document with id XXX rather than the document which was processed to emit the key/value pair. This means that if one document contains the ids of other documents, it can cause those documents to be fetched in the view too, adjacent to the same key if required. For example, if you have the following hierarchically-linked documents: [ { "_id": "11111" }, { "_id": "22222", "ancestors": ["11111"], "value": "hello" }, { "_id": "33333", "ancestors": ["22222","11111"], "value": "world" } ] you can emit the values with the ancestor documents adjacent to them in the view like this: function(doc) { if (doc.value) { emit([doc.value, 0], null); if (doc.ancestors) { for (var i in doc.ancestors) { emit([doc.value, Number(i)+1], {_id: doc.ancestors[i]}); } } } } more at http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views ken tyler On Wed, Sep 15, 2010 at 2:10 PM, 7zark7 <7zark7@gmail.com> wrote: > Given doc type A and B: > > A has a 1-to-many relationship with B (each A knows of many Bs) > Each B can be known by many As, but does not know which. > A has an array of its known B keys. > > A doc: > { > "_id": "...", > "kind": "A", > "b_IDs": ["...", "...", "...", "..."] > } > > > B doc: > { > "_id": "...", > "kind": "B" > } > > > If I know the key for A, how can I retrieve all related Bs in one view or > list call? > I'd like to avoid middle-ware that makes sequential calls. > > Thanks! > --0016363b9a587100f5049052df08--