Generally speaking, many-to-many is simply not possible in stock CouchDB. You seem like somebody who just wants it straight with no sugar coating, so there it is.
Joining related data is not a strength of CouchDB, and of course it is the primary strength of relational databases. However, this fact is muddied a little bit because most people "intuitively" model their data relationally because that's how we're all trained.
Your difficulty is precisely the cost you must pay to CouchDB to get its other features: HTTP API, flexible clustered, multi-master, or offline operation, etc. By design, its sync features are possible because documents are simple, and unrelated to each other.
However, another strength of CouchDB is concurrency. So if you are already enjoying CouchDB's other features, and you just need to get over this one hump, you might simply "join" on the client side.
A simpler map function simply emits all the froms (key:["from", "A"], value:"whatever1"
) and tos (key:["to","B"], value:"whatever3"
). Thus you can query it with ?key=["from","A"]
and get a list of all whatevers for any given from or to value.
For each link document, you have a from and to value to check. Thus, query both (either one at a time, or simultaneously, which is quite easy in Javascript for example):
- The view with option
?key=["from","A"]
- And also the view with
?key=["to","B"]
And once both results return, you have the answer for that link.
You will find that, since you may only make efficient requests from CouchDB (index scans), CouchDB can support a very high rate of requests and a high number of concurrent connections.
Is this easy? In Javascript, it's not so bad, but no, basically it is not easy. This question is fundamentally cutting against the CouchDB grain and with the relational grain. (I am personally excited about Drizzle for problems like this.)