steve
steve

Reputation: 21

list function in couch db getting a expression does not evaluate to a function error

I am a newbie to couchdb I copied and pasted a simple list function from couchdb wiki and i am
getting a expression does not evaluate to function error in my browser this is my code in couch I included the whole document

    {
   "_id": "_design/recipies",
   "_rev": "44-58a0833eb8834e801ca23f6fc82c2a6a",
   "language": "javascript",
   "views": {
       "cup": {
           "map": "function(doc) {\n\tif(doc.ingredients){\n\t\tfor (ingredient in doc.ingredients){\n\t\t\tif(doc.ingredients[ingredient].cup){\n\t\t\t\tvalue = ingredient;\n\t\t\t\tkey = doc.ingredients[ingredient].cup;\nemit(key, value);}\n\t\t}\n\t}\n\n\n  \n}"
       }
   },
   "lists": {
       "index-posts": "function(doc, req) {provides('html', function() {var html = '<html><body><ol>\n'; while (row === getRow()) { html += '<li>' + row.key + ':' + row.value + '</li>\n';} html += '</ol></body></head>';return html;});}"
   }
}

This is the error i am getting in my browser

{"error":"compilation_error","reason":"Expression does not eval to a function. (function(doc, req) {provides('html', function() {var html = '<html><body><ol>\n'; while (row === getRow()) { html += '<li>' + row.key + ':' + row.value + '</li>\n';} html += '</ol></body></head>';return html;});})"}

I would like to know what is wrong with the function thanks

Upvotes: 1

Views: 717

Answers (1)

Matt Jennings
Matt Jennings

Reputation: 1148

You need to call:

while (row = getRow()){

instead of:

while (row === getRow()){

And your newline characters within quoted strings need to be escaped:

'<li>' + row.key + ':' + row.value + '</li>\\n'

Upvotes: 3

Related Questions