couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Wolff <awo...@gmail.com>
Subject Querying by foreign keys
Date Sat, 25 Apr 2009 17:27:33 GMT
Hi list,
I have a little query problem that would be easy to solve in SQL, but
seems hard in CouchDB. I have data that looks like this:
doc1: {
   keys : [1,2,3],
   data : ....
}
doc2: {
   keys : [1,3,5],
   data : ....
}
...

I'd like a view of my documents that lets me filter on multiple keys,
so a query of keys=[1] yields doc1,doc2, as does a query of
keys=[1,3]. keys=[2] would just fetch doc1, etc. Documents commonly
have 1-5 keys, but may have thousands.

In SQL, this would be easy to model by making a table of doc.id,key.
In couch, the only way I can think of to truly index all the
combinations of the keys is to emit the n! combinations of the keys,
which seems like a bad idea. (Maybe it's not though?)

So far, the best solution we've thought of is to emit the document for
each key. We would use the information about key frequency to be smart
about fetching an initial list of documents, and then do the rest of
the filtering in the app.

Any advice here? I looked at
http://wiki.apache.org/couchdb/EntityRelationship, but there's no
entry on querying by foreign keys. If we come up with something good
(or even just definitive), of course I'll add it to the wiki.

Thanks!
A

Mime
View raw message