couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <>
Subject Re: Conditional joins
Date Fri, 17 Sep 2010 13:40:24 GMT
Hi Simon,

You're trying to apply information from one document onto all your documents. This means you'll
need to do two queries, one for each information extraction.

You need a view with the domains only showing per status:
function(doc) { doc.type=="domain" && doc.status == 1 && emit (doc.domain,
null); }

Then you need a view with the users by domain:
function(doc) { doc.type=="user" && emit (doc.domain, doc); }

So you query the first view for all active domains, and then you query the second view with
those domains as the keys.


On Sep 17, 2010, at 15:04 , Simon Woodhead 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 where parent.status=1;
> I've read the 'join' documentation (e.g.
> 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":"","status":1},
> {"_id":"45a6951b34a6f45bd44fd169c00046db","_rev":"1-37eaf0c4944dac9f5fe07b25c0b68b1d","type":"domain","domain":"","status":0},
> {"_id":"45a6951b34a6f45bd44fd169c00053d9","_rev":"3-729f46c86ee4984941939c65787126fb","type":"user","domain":"","user":"foo","password":"test123"},
> {"_id":"45a6951b34a6f45bd44fd169c00060c8","_rev":"1-46997eba12e7adbb6e9266a1fe83c42d","type":"user","domain":"","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 but
> not for
> 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.

View raw message