tags:

views:

292

answers:

1

Hi Guys,

I'm new to CouchDB and I know my mindset is probably still too much in the relational DB sphere, but here goes:

It appears that querying on Couch is all done via Views. I read that temporary views are very inefficient and should be avoided in production.

So my question really is how would one do effective querying with parameters (as the views do not accept them). For example if I were to use Couch to power a blog site would I have to create a new view for each post equivalent to 'select post from posts where id=1'.

I understand that I can use lucene along side the querying to perfom a full text search on the results, but this is only really useful for textual content not numbers.

Im happy creating a boat load of static views as they can be created very simply on the fly. My worry is that this is not how Couch was supposed to be used and I'm missing something. Feel free to enlighten me.

Cheers, Chris.

+2  A: 

Views do accept url parameters, key being the one your are looking for. You can even limit how many rows you get and sort as well.

Your views can be indexed by arbitrary JSON keys. This means you can create a view that emits documents like so, [username docid] => doc. Then you can query this view with http://url/to/view?key=[username docid].

You could create a view that emits [username type date] => doc. Now you can get all documents of a certain between a certain date (using startKey and endKey url parameters).

Your example of the blog is one that CouchDB is particularly well suited for. In fact I believe it's an example in the upcoming CouchDB book from O'reilly.

That said, some kinds of queries are not easily handled by CouchDB alone. couchdb-lucene can help here. Don't assume that's it's only good for full text search. I've been using it to run general complex queries against the database to good effect.

dnolen