You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Joel Reed <jo...@visn.biz> on 2008/08/20 17:21:52 UTC
Creating a permanent view
I've been poking around on the wiki site and googling for answers, but
can't quite come up with the right syntax yet to create a permanent view
and then GET the results.
I have a "test.view" file that looks like this:
{
"_id":"_design/forms",
"_rev":"12345",
"views":
{
"all": {
"map": "function(doc) { emit(doc.Patient, doc);
}"
}
}
}
Then I say:
curl -v -H 'Content-Type: application/json;'
"http://localhost:5984/cs-cache/" --data-binary @/home/jreed/test.view
They I try to fire up:
http://localhost:5984/cs-cache/_view/_design/forms/all
And get a lengthy error message:
{"error":"EXIT","reason":"{function_clause,\n [{couch_httpd,handle_db_request,\n
[{mochiweb_request,#Port<0.349>,'GET',\n
\"\/cs-cache\/_view\/_design\/forms\/all\",\n
{1,1},\n {9,\n {\"host\",\n
{'Host',\"localhost:5984\"},\n {\"accept\",\n
{'Accept',\n \"text\/html,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8\"},\n
nil,\n {\"accept-language\",\n
{'Accept-Language',\"en-us,en;q=0.5\"},\n
{\"accept-encoding\",\n
{'Accept-Encoding',\"gzip,deflate\"},\n
{\"accept-charset\",\n
{'Accept-Charset',\"ISO-8859-1,utf-8;q=0.7,*;q=0.7\"},\n
nil,nil},\n nil},\n {\"connection\",\n
{'Connection',\"keep-alive\"},\n nil,\n
{\"cookie\",\n {'Cookie',\n
\"sessionId=cca8e4b9-0de4-4d71-9bf0-f4aeb382dde7\"},\n nil,nil}}}},\n
{\"user-agent\",\n {'User-Agent',\n
\"Mozilla\/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko\/2008071816
Ubuntu\/8.10 (intrepid) Firefox\/3.0.1\"},\n
{\"keep-alive\",{'Keep-Alive',\"300\"},nil,nil},\n nil}}}},\n
'GET',\n {\"cs-cache\",<0.230.0>,[\"_view\",\"_design\",\"forms\",\"all\"]}]},\n
{couch_httpd,handle_request,2},\n {mochiweb_http,headers,4},\n {proc_lib,init_p,5}]}"}
Can anyone point out my error? Most google examples I see are doing _temp_view stuff.
jr
Re: Creating a permanent view
Posted by Chris Anderson <jc...@grabb.it>.
Joel,
For simple editing tasks like this, I tend to use the Futon web interface:
http://localhost:5984/_utils/
I'm guessing you've already been using it, but it doesn't hurt to put
it in the thread here.
On Wed, Aug 20, 2008 at 11:23 AM, Joel Reed <jo...@visn.biz> wrote:
> Joel Reed wrote:
>>
>> I've been poking around on the wiki site and googling for answers, but
>> can't quite come up with the right syntax yet to create a permanent view and
>> then GET the results.
>>
>> I have a "test.view" file that looks like this:
>>
>> {
>> "_id":"_design/forms",
>> "_rev":"12345",
>> "views":
>> {
>> "all": {
>> "map": "function(doc) { emit(doc.Patient, doc); }"
>> }
>> }
>> }
>>
>> Then I say:
>>
>> curl -v -H 'Content-Type: application/json;'
>> "http://localhost:5984/cs-cache/" --data-binary @/home/jreed/test.view
>>
>> They I try to fire up:
>> http://localhost:5984/cs-cache/_view/_design/forms/all
>
> Ok, I figured out what I was doing wrong. The correct steps appear to be:
>
> 1) Create a test.view file WITHOUT a "_rev" entry that looks like this:
>
> {
> "_id":"_design/forms",
> "views":
> {
> "all": {
> "map": "function(doc) { log(doc); emit(doc.Patient, doc); }"
> }
> }
> }
>
> 2) Submit to couchdb with curl like this:
>
> curl -v -X PUT -H 'Content-Type: application/json'
> http://localhost:5984/cs-cache/_design/forms -T /home/jreed/test.view
>
> 3) test the view using a URL like this:
>
> http://localhost:5984/cs-cache/_view/forms/all
>
> Thanks Jan for helping me on the last step. I'm very new to couchdb, thus my
> confusion.
>
> jr
>
--
Chris Anderson
http://jchris.mfdz.com
Re: Creating a permanent view
Posted by Joel Reed <jo...@visn.biz>.
Joel Reed wrote:
> I've been poking around on the wiki site and googling for answers, but
> can't quite come up with the right syntax yet to create a permanent
> view and then GET the results.
>
> I have a "test.view" file that looks like this:
>
> {
> "_id":"_design/forms",
> "_rev":"12345",
> "views":
> {
> "all": {
> "map": "function(doc) { emit(doc.Patient, doc);
> }" }
> }
> }
>
> Then I say:
>
> curl -v -H 'Content-Type: application/json;'
> "http://localhost:5984/cs-cache/" --data-binary @/home/jreed/test.view
>
> They I try to fire up:
> http://localhost:5984/cs-cache/_view/_design/forms/all
Ok, I figured out what I was doing wrong. The correct steps appear to be:
1) Create a test.view file WITHOUT a "_rev" entry that looks like this:
{
"_id":"_design/forms",
"views":
{
"all": {
"map": "function(doc) { log(doc); emit(doc.Patient, doc); }"
}
}
}
2) Submit to couchdb with curl like this:
curl -v -X PUT -H 'Content-Type: application/json'
http://localhost:5984/cs-cache/_design/forms -T /home/jreed/test.view
3) test the view using a URL like this:
http://localhost:5984/cs-cache/_view/forms/all
Thanks Jan for helping me on the last step. I'm very new to couchdb,
thus my confusion.
jr
Re: Creating a permanent view
Posted by Joel Reed <jo...@visn.biz>.
Jan Lehnardt wrote:
>>
>> They I try to fire up:
>> http://localhost:5984/cs-cache/_view/_design/forms/all
>
> Try http://localhost:5984/cs-cache/_view/forms/all
That gives me:
{"error":"not_found","reason":"missing"}
I must be doing something else wrong. Darn.
Thanks for the suggestion.
jr
Re: Creating a permanent view
Posted by Jan Lehnardt <ja...@apache.org>.
On Aug 20, 2008, at 17:21, Joel Reed wrote:
> I've been poking around on the wiki site and googling for answers,
> but can't quite come up with the right syntax yet to create a
> permanent view and then GET the results.
>
> [...]
>
>
> They I try to fire up:
> http://localhost:5984/cs-cache/_view/_design/forms/all
Try http://localhost:5984/cs-cache/_view/forms/all
Cheers
Jan
--