Hi,
I'm pretty new to CouchDB so please pardon me if this is a silly
question, but can you connect the results of one view to another?
Do you mean something like chaining the views? Then I guess the
preferred way is to store the view result as documents again. The
second view could then use these documents as basis of its computation.
Imagine I have a bunch of children documents and each child has a
favorite color. I also have a bunch of toy documents and each toy
has a
color. I want to build a list of what toys each child will like
based on
its color.
I can make a view to emit(color, name) for each toy and something
similar for each child. But then do I have to connect the two in my
code? If your dataset gets large that seems like a lot of work gets
pushed out to the client end. Is there any way to construct a view
that
links these together?
AFAIK this has to be done on the client side. But you could do
something like this:
map = function(doc) {
if( doc.type=="TOY" ) {
emit( [doc.color, "T", doc.name], null );
} else if( doc.type=="CHILD" ) {
emit( [doc.color, "C", doc.name], null );
}
}
Then you could use the view collation and query the view like this:
/db/_design/tmp/toys?startkey=[GREEN]&endkey=[GREEN, "T", {}]
This would give you a list of all toys being green and all children
with green as their favorite color. The join would still have to be
done on the client side though.
Maybe with some more time investigating this someone could come up
with a better idea... :)
Daniel