Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't any CouchDB _list function to work

Struggling to get any list function to work. I've been fine with _show and _view functions, but lists don't seem to be working, or I have misunderstood what to do! (I'll admit to needing an idiot's guide!)

My design document looks like:

{
   "_id": "_design/lists",
   "_rev": "3-d22225b4a28a6ca11484723c3a37201b",
   "language": "javascript",
   "views": {
       "variants": {
           "map": "function(doc) { emit(doc.var, doc.number_of_results); }"
       }
   },
   "lists": {
       "results": "function(head, req) { var row; while(row = getRow()) {send(row.value);}}"
   }
}

When I enter http://localhost:5984/mydb/_design/lists/_view/variants I get a list of variant names, like:

...{"id":"f050ad9b9f725443cb8c4071f40583b","key":"rs1013940","value":19008},
{"id":"f050ad9b9f725443cb8c4071f40daff","key":"rs1013940","value":19008},
{"id":"f050ad9b9f725443cb8c4071f40b985","key":"rs1021188","value":10197}...

but when I enter http://localhost:5984/mydb/_design/lists/_list/results I get:

{"error":"list_error","reason":"Invalid path."}

Does anyone know what I'm doing wrong? I've tried everything I can think of and swapping the function for one from any of the online tutorials.

I'm using CouchDB version 1.0.1 on Ubuntu 12.04

Many thanks, hope someone can help!

like image 311
raistrick Avatar asked Jul 03 '12 12:07

raistrick


2 Answers

You need to include both a view name as well as a list name in your URL:

http://localhost:5984/:db/_design/:ddoc/_list/:list/:view

which in your case translates to:

http://localhost:5984/mydb/_design/lists/_list/results/variants

like image 101
Dominic Barnes Avatar answered Sep 21 '22 06:09

Dominic Barnes


I had the exact same condundrum; It wasn't easy to immediatley discern the difference in using views, shows, and lists from a beginner's perspective. In the offical docs I read this:

While Show functions are used to customize document presentation, List functions are used for same purpose, but against View functions results.

And it confused me slightly. I thought similarly that one could use a list alone to collate documents, perhaps in a nice juicy HTML coating, but I really only figured out what was going on after reading this page of the definitive guide (which is an incredible resource!)

http://guide.couchdb.org/draft/transforming.html

Like Dominic says, it should have been obvious to me based on the API :)

like image 22
Steve Benner Avatar answered Sep 22 '22 06:09

Steve Benner