couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas <>
Subject View related question (getting /database/slug in addition to /database/id)
Date Mon, 02 Mar 2009 23:52:12 GMT

I am just starting to play with CouchDB and I read a lot of blog posts, 
apache's wiki pages and the published pages of the upcoming book. So far 
it feels weird (always worked with relational databases), but I am 
learning fast I think.

I have a question I could't find an answer to, I hope it doesn't sound 
too dumb ;-)

Let's say I have this database, I have an id, a title, a slug and a 
body. If I GET /database/id it works just fine, however I'd like to be 
able to GET /database/slug as well. How do I go for it?

I realize I could set an arbitrary "id", so that I could GET 
/database/sometext and pretend it was the slug while I am actually 
calling an id, but I'd like to be able to do both.

I also know I could create a view like this:

function(doc) {
   if(doc.slug) {
     emit(doc.slug, null);

to get all the items with a given slug (GET 
/database/_view/posts/by_slug/?key="sometext"), but the slug is going to 
be a unique string, so it seems a superflous method. By the way: why do 
I have to pass quotes to the key value? Am I doing something wrong with 
this view?

So: is there any way for me to GET /database/slug in addition to GET 
/database/id ?



View raw message