couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Re: equivalent of JOINs in couchdb?
Date Fri, 13 Mar 2009 12:51:17 GMT
On Mar 13, 2009, at 12:59 PM, Anand Chitipothu wrote:

> I have been reading about couchdb and trying understand how it works.
> One thing that i'm unable to understand is how to do equivalent of
> JOINs in couchdb.
>
> Let me explain what I need with an example.
> I want to store books in couchdb with each book having title, authors,
> isbn, lccn, publisher and many other fields.
> I would like to be able to query the system for any combination of
> these. some thing like:
>
> type="book" and publisher="foo" and author="bar
> type="book" and isbn="1234567890"
>
> How to do this in couchdb?

To begin with, since ISBN is supposed to be unique per book, you can  
make that be the DocID for the documents. That way you can simply look  
for a certain ISBN number and get an answer instantly.

Then you need to look at your application and see which view indexes  
you need. Each index (created by map()) allows you to search for the  
indexed fields at the expense of diskspace. You can use complex keys  
like [doc.date,doc.author] to find books sorted by date and then by  
author. To find anything released since a certain date you would  
specify a startkey of ["<date>",""].

Your application then has to filter out the results further, so it  
pays to look for the fields that you will be sorting on and that will  
divide the search space in the smallest blocks.

Note that it looks like you will do a lot of text searches. Have a  
look at http://github.com/rnewson/couchdb-lucene/tree/master which is  
better suited for that.

> I wouldn't want to create a temporary view for running each query as
> it is very expensive.

You're right, it is. Only use those for development.

Wout.
Mime
View raw message