You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Matthew Woodward <ma...@mattwoodward.com> on 2012/02/22 18:28:29 UTC

Re: how i can do a join in couchdb ?

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

Re: how i can do a join in couchdb ?

Posted by Anthony <as...@uci.cu>.
El 22/02/2012 13:28, Matthew Woodward escribió:
>   document and its child
> documents, then the next parent and its ch
thank :D , a can understand better, and saw the

"CouchDB: The Definitive
Guide too

regards from cuba
anthony



Fin a la injusticia, LIBERTAD AHORA A NUESTROS CINCO COMPATRIOTAS QUE SE ENCUENTRAN INJUSTAMENTE EN PRISIONES DE LOS EEUU!
http://www.antiterroristas.cu
http://justiciaparaloscinco.wordpress.com