Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 881939A23 for ; Wed, 22 Feb 2012 17:28:59 +0000 (UTC) Received: (qmail 30116 invoked by uid 500); 22 Feb 2012 17:28:57 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 30076 invoked by uid 500); 22 Feb 2012 17:28:57 -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 30067 invoked by uid 99); 22 Feb 2012 17:28:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2012 17:28:57 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=FSL_RCVD_USER,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.220.180] (HELO mail-vx0-f180.google.com) (209.85.220.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2012 17:28:51 +0000 Received: by vcbfo1 with SMTP id fo1so308010vcb.11 for ; Wed, 22 Feb 2012 09:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of matt@mattwoodward.com designates 10.52.35.69 as permitted sender) client-ip=10.52.35.69; Authentication-Results: mr.google.com; spf=pass (google.com: domain of matt@mattwoodward.com designates 10.52.35.69 as permitted sender) smtp.mail=matt@mattwoodward.com Received: from mr.google.com ([10.52.35.69]) by 10.52.35.69 with SMTP id f5mr15263422vdj.29.1329931710221 (num_hops = 1); Wed, 22 Feb 2012 09:28:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.52.35.69 with SMTP id f5mr12486147vdj.29.1329931709919; Wed, 22 Feb 2012 09:28:29 -0800 (PST) Received: by 10.52.162.225 with HTTP; Wed, 22 Feb 2012 09:28:29 -0800 (PST) X-Originating-IP: [50.132.52.46] In-Reply-To: References: <4F4416CA.7090208@uci.cu> Date: Wed, 22 Feb 2012 09:28:29 -0800 Message-ID: Subject: Re: how i can do a join in couchdb ? From: Matthew Woodward To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=20cf307cfcd425308d04b990db2d X-Gm-Message-State: ALoCoQnH8IqVJpKLPC/yc79XIuqS/fVOIkkQqlvTNBR4ZHenMAXfVF0E0WVbrAwDCkkMXznQCP08 --20cf307cfcd425308d04b990db2d Content-Type: text/plain; charset=ISO-8859-1 Without addressing your exact situation, the gist is you have your view output they key in such a way that things are grouped/joined appropriately. Simple example, say you want to output a parent document and its child documents, then the next parent and its child documents. Assume parent document has an ID, and child document has the parent ID in it as the field "parentID". Also assume that each document has a type field, and in this example we'll use types of "parent" and "child." In your view you'd do something like: if (doc.type == 'parent') { emit([doc._id, 0], ... whatever value you want here ...); } else if (doc.type == 'child') { emit([doc.parentID, 1], ... whatever value you want here ...); } That will render the parent followed by its children because the view will be collated on parent ID and 0 first, then parent ID and 1 next, due to the array key of a matching ID and then the 0 and 1 integers. Since the view is sorted based on that array key everything in the output is grouped properly. -- Matthew Woodward matt@mattwoodward.com http://blog.mattwoodward.com identi.ca / Twitter: @mpwoodward Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments. http://www.gnu.org/philosophy/no-word-attachments.html --20cf307cfcd425308d04b990db2d--