I am now working with filters. I have created a small handful of docs. Each
one consists of an array of fields. A sample of one is below:
{ "_id": "101", "_rev": "1-b3303229104420834b1cf8fd22a75676", "name": "101",
"flds": [ "10", "11", "aa", "bb" ] }
And here is the filter function I am using (in a design called "lookup"):
"filters": { "getdoc": "function(doc, req) {
log(doc.flds[1]);
return true;}" }
I get the correct response for the URL:
http://localhost:5984/db/_changes?filter=/lookup/getdoc, with a code of 200.
And the function *does* log "doc.flds[1]" as expected.
Then the log shows a server error 500, reporting that "doc.flds" in undefined.
All occurring within one HTTP request.
The full log of the error is below (complete with line wrapping). Is something
broken? Or am I doing something incorrect?
Thanks for any advice.
-Scott
[info] [<0.2067.0>] 127.0.0.1 - - GET /db/_changes?filter=/lookup/getdoc 200
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 11
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 12
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 13
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 14
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 15
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 16
[info] [<0.200.0>] OS Process #Port<0.5107> Log :: 17
[error] [<0.2067.0>] OS Process Error <0.200.0> :: {<<"TypeError">>,
{[{<<"message">>,
<<"doc.flds is undefined">>},
{<<"fileName">>,
<<"filters.getdoc">>},
{<<"lineNumber">>,1},
{<<"stack">>,
<<"([object Object],[object Object])@filters.getdoc:1\n(function (doc, req)
{log(doc.flds[1]);return true;},[object Object],[object
Array])@../share/couchdb/server/main.js:510\n(\"_design/lookup\",[object
Array],[object
Array])@../share/couchdb/server/main.js:1517\n()@../share/couchdb/server/main.js:1562\n@../share/couchdb/server/main.js:1573\n">>}]}}
[info] [<0.2067.0>] 127.0.0.1 - - GET /db/_changes?filter=/lookup/getdoc 500
[error] [<0.2067.0>] httpd 500 error response:
{"error":"TypeError","reason":"{[{<<\"message\">>,<<\"doc.flds is
undefined\">>},\n {<<\"fileName\">>,<<\"filters.getdoc\">>},\n
{<<\"lineNumber\">>,1},\n {<<\"stack\">>,\n <<\"([object Object],[object
Object])@filters.getdoc:1\\n(function (doc, req) {log(doc.flds[1]);return
true;},[object Object],[object
Array])@../share/couchdb/server/main.js:510\\n(\\\"_design/lookup\\\",[object
Array],[object
Array])@../share/couchdb/server/main.js:1517\\n()@../share/couchdb/server/main.js:1562\\n@../share/couchdb/server/main.js:1573\\n\">>}]}"}