Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 6710 invoked from network); 20 Sep 2010 21:05:22 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 20 Sep 2010 21:05:22 -0000 Received: (qmail 76804 invoked by uid 500); 20 Sep 2010 21:05:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 76683 invoked by uid 500); 20 Sep 2010 21:05:20 -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 76675 invoked by uid 99); 20 Sep 2010 21:05:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Sep 2010 21:05:20 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of simon.woodhead@simwood.com designates 64.18.2.175 as permitted sender) Received: from [64.18.2.175] (HELO exprod7og111.obsmtp.com) (64.18.2.175) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 20 Sep 2010 21:05:13 +0000 Received: from source ([209.85.212.43]) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTJfMcyZIbfzqQ/PCBCXopqSunUlAtaX0@postini.com; Mon, 20 Sep 2010 14:04:53 PDT Received: by vws8 with SMTP id 8so4319877vws.30 for ; Mon, 20 Sep 2010 14:04:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.63.79 with SMTP id a15mr4849749vci.61.1285016689947; Mon, 20 Sep 2010 14:04:49 -0700 (PDT) Received: by 10.220.194.198 with HTTP; Mon, 20 Sep 2010 14:04:49 -0700 (PDT) In-Reply-To: References: Date: Mon, 20 Sep 2010 22:04:49 +0100 Message-ID: Subject: Re: Conditional joins From: Simon Woodhead To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=e0cb4e887cb555b60f0490b743aa X-Virus-Checked: Checked by ClamAV on apache.org --e0cb4e887cb555b60f0490b743aa Content-Type: text/plain; charset=ISO-8859-1 Thanks for the great comments guys. I think I'll run with the two view approach. cheers, Simon On Fri, Sep 17, 2010 at 3:08 PM, Kenneth Tyler wrote: > Sorry, > I missed an important part of your question. > Two views would work. It might be that building a composite key would also > work, since you have the domain information in all the user documents. > function(doc){if(doc.type=='user'){emit([doc.domain,doc.status],doc)} > > and then query the view looking for [test.com,1] > > ken tyler > > On Fri, Sep 17, 2010 at 6:56 AM, Kenneth Tyler wrote: > > > Simon, > > I think this is a case where the flat document structure of couch > documents > > makes things much simpler than in SQL. > > > > If you had a view like this: > > function(doc){if(doc.type=='user'){emit(doc.status,doc)} > > then it would return all the user documents with their status as their > key > > and you could use ?key="1" (i think the quotes are necessary) to get all > > the users whose status is 1 > > > > if you want to do the same thing for domains, you just write a "domain" > > view that returns status as the key > > > > ken tyler > > > > > > On Fri, Sep 17, 2010 at 6:04 AM, Simon Woodhead < > > simon.woodhead@simwood.com> wrote: > > > >> Hi folks, > >> > >> I'm pretty green with views and have a need to do a join with results > >> from one side returned if a condition is met on the other. In SQL I'd > >> do: > >> > >> select * from child join parent on child.id=parent.id where > >> parent.status=1; > >> > >> I've read the 'join' documentation (e.g. > >> http://www.cmlenz.net/archives/2007/10/couchdb-joins) and can return > >> documents of multiple types with matching keys ok. What I can't do is > >> do the same but only if the parent matches a condition. > >> > >> Specifically, my data is like: > >> > >> > >> > {"45a6951b34a6f45bd44fd169c0003f9c","_rev":"1-6c88818b43d562c45e452bf00db06ee2","type":"domain","domain":" > >> test.com","status":1}, > >> > >> > {"_id":"45a6951b34a6f45bd44fd169c00046db","_rev":"1-37eaf0c4944dac9f5fe07b25c0b68b1d","type":"domain","domain":" > >> test2.com","status":0}, > >> > >> > {"_id":"45a6951b34a6f45bd44fd169c00053d9","_rev":"3-729f46c86ee4984941939c65787126fb","type":"user","domain":" > >> test.com","user":"foo","password":"test123"}, > >> > >> > {"_id":"45a6951b34a6f45bd44fd169c00060c8","_rev":"1-46997eba12e7adbb6e9266a1fe83c42d","type":"user","domain":" > >> test2.com","user":"bar","password":"test123"} > >> > >> I want to be be able to query a view by domain and see all users for > >> it if the status is 1. So in this case I'd see users for test.com but > >> not for test2.com. > >> Any help would be appreciated. > >> > >> Thanks! > >> Simon > >> -- > >> ***** Email confidentiality notice ***** > >> > >> This message is private and confidential. If you have received this > >> message in error, please notify us and remove it from your system. > >> > >> > >> Simwood eSMS Limited is a limited company registered in England and > Wales. > >> Registered number: 03379831. Registered office: c/o HW Chartered > >> Accountants, Keepers Lane, The Wergs, Wolverhampton, WV6 8UA. Trading > >> address: Falcon Drive, Cardiff Bay, Cardiff, CF10 4RU. > >> > >> > >> > > > -- ***** Email confidentiality notice ***** This message is private and confidential. If you have received this message in error, please notify us and remove it from your system. Simwood eSMS Limited is a limited company registered in England and Wales. Registered number: 03379831. Registered office: c/o HW Chartered Accountants, Keepers Lane, The Wergs, Wolverhampton, WV6 8UA. Trading address: Falcon Drive, Cardiff Bay, Cardiff, CF10 4RU. --e0cb4e887cb555b60f0490b743aa--