I use what seems like a general trick to create a connection view:
function(doc) {
if (doc.Type == "customer") {
emit([doc._id, 0], doc);
} else if (doc.Type == "order") {
emit([doc.customer_id, 1], doc);
}
}
I know that I can use the following query to get one customerand all related Orders:
?startkey=["some_customer_id"]&endkey=["some_customer_id", 2]
But now I have very closely linked my request to the view code. Is there any value that I can put where I put my " 2" to more clearly say: "I want everything to be tied to this client"? I think I saw
?startkey=["some_customer_id"]&endkey=["some_customer_id", {}]
But I'm not sure what {}will definitely sort out after everything else.
Confirm cmlenz for the join method.
Further explanation from the CouchDB page in the mapping :
startkey=["foo"]&endkey=["foo",{}] "foo" , ["foo","bar"] ["foo",["bar","baz"]]. ["foo",{"an":"object"}]
{} , .