incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <>
Subject Re: Querying by foreign keys
Date Sat, 25 Apr 2009 18:01:58 GMT

Yeah, this is one of the harder bits to do in CouchDB at the moment.
Your two best bets are either to use something like couchdb-lucene or
as you mentioned to pay attention to the key frequencies for smarter
retrieval and then do client side filtering.

Paul Davis

On Sat, Apr 25, 2009 at 1:27 PM, Adam Wolff <> wrote:
> 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,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
>, 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

View raw message