Paul,
Thanks.. I put into my views field
{
"vartest": {
"map": "function (doc) { emit([doc.FolkCde, doc.Latitude,
doc.Longitude], doc._id )}"
}
}
but if I try either of:
5984/lith/_view/test2/vartest?startkey=["sM"]&endkey=["sM",{},{}]
5984/lith/_view/test2/vartest?startkey=[sM]&endkey=[sM,{},{}]
I get errors (URL and errors at end of email)
I tried the quotes in the first one since the reference Bahadri, sent me
to noted that the values to startkey endkey and key need to be JSON encoded.
I also tried just 5984/lith/_view/test2/vartest?key="sM" (and =sM)
I am running version 0.8.0 if that make any difference in this.
Have I just gotten a syntax error some place?
Thanks
Doug
Using: 5984/lith/_view/test2/vartest?startkey=["sM"]&endkey=["sM",{},{}]
[Thu, 16 Oct 2008 17:40:10 GMT] [info] [<0.26680.1>] Spawning new
javascript instance.
[Thu, 16 Oct 2008 17:40:10 GMT] [info] [<0.26670.1>] HTTP Error (code
500): {{nocatch,{bad_value,
"Cannot encode 'undefined' value as
JSON"}},
[{couch_query_servers,prompt,2},
{couch_query_servers,'-map_docs/2-fun-0-',2},
{lists,map,2},
{lists,map,2},
{couch_query_servers,map_docs,2},
{couch_view,view_compute,2},
{couch_view,update_group,1},
{couch_view,update_loop,5}]}
[Thu, 16 Oct 2008 17:40:10 GMT] [error] [emulator] Error in process
<0.26680.1> with exit value: {{nocatch,{bad_value,"Cannot encode
'undefined' value as
JSON"}},[{couch_query_servers,prompt,2},{couch_query_servers,'-map_docs/2-fun-0-',2},{lists,map,2},{lists,map,2},{couch_query_servers,map_docs,2},{couch_view,view_compute...
[Thu, 16 Oct 2008 17:40:10 GMT] [info] [<0.26670.1>] 129.186.121.156 - -
"GET /lith/_view/test2/vartest" 500
Using: 5984/lith/_view/test2/vartest?startkey=[sM]&endkey=[sM,{},{}]
[Thu, 16 Oct 2008 17:41:11 GMT] [info] [<0.26676.1>] HTTP Error (code
500): {'EXIT',{function_clause,
[{cjson,
tokenize,
["sM]",{decoder,utf8,null,1,2,any}]},
{cjson,decode_array,3},
{cjson,json_decode,2},
{couch_httpd,
'-parse_view_query/1-fun-0-',
2},
{lists,foldl,3},
{couch_httpd,handle_db_request,3},
{couch_httpd,handle_request,2},
{mochiweb_http,headers,4}]}}
[Thu, 16 Oct 2008 17:41:11 GMT] [info] [<0.26676.1>] 129.186.121.156 - -
"GET /lith/_view/test2/vartest" 500
Using: 5984/lith/_view/test2/vartest?key="sM"
[Thu, 16 Oct 2008 17:42:29 GMT] [info] [<0.26690.1>] Spawning new
javascript instance.
[Thu, 16 Oct 2008 17:42:29 GMT] [info] [<0.26682.1>] HTTP Error (code
500): {{nocatch,{bad_value,
"Cannot encode 'undefined' value as
JSON"}},
[{couch_query_servers,prompt,2},
{couch_query_servers,'-map_docs/2-fun-0-',2},
{lists,map,2},
{lists,map,2},
{couch_query_servers,map_docs,2},
{couch_view,view_compute,2},
{couch_view,update_group,1},
{couch_view,update_loop,5}]}
[Thu, 16 Oct 2008 17:42:29 GMT] [info] [<0.26682.1>] 129.186.121.156 - -
"GET /lith/_view/test2/vartest" 500
[Thu, 16 Oct 2008 17:42:29 GMT] [error] [emulator] Error in process
<0.26690.1> with exit value: {{nocatch,{bad_value,"Cannot encode
'undefined' value as
JSON"}},[{couch_query_servers,prompt,2},{couch_query_servers,'-map_docs/2-fun-0-',2},{lists,map,2},{lists,map,2},{couch_query_servers,map_docs,2},{couch_view,view_compute...
Paul Carey wrote:
I have set up a test server and I am able to store and call simple views
like:
function(doc) { if (doc.FolkCde == 'S') emit(doc.Latitude, doc.Longitude)
}
However, I am curious if it's possible for couchdb to be sent arguments to
a view? For example could I do something like:
...:5984/lith/_view/test/v2/Mn where the "Mn" argument is passed in and
used for the doc.FolkCdr comparison?
Not with the view you've defined, but you could try something like
function (doc) {
emit( [doc.FolkCde, doc.lat, doc.lng], doc._id );
}
and then query it with
_view/test/v2?startkey=[$folkCde]&endkey=[$folkCde,{},{}]
where the {} in the endkey sort very late
The emit above emits the doc id rather than the doc itself as you said
you've got very large quantities of data. Emitting the doc could make
the view very large.
couchdb: semi-dynamic and semi-structured data, static queries
RDMS: semi-static (and well structured) data, dynamic queries
Sounds reasonable, I've heard others describe it this way too.
Paul