当前位置: 动力学知识库 > 问答 > 编程问答 >

couchdb - Couch db returns a does not eval to a function

问题描述:

I got this code

 {

"_id": "_design/test",

"_rev": "10-651aa6314effdad0bca00fc4a3da38f6",

"views": {

"foo": {

"map": "(function(doc){ emit(doc._id, doc._rev)})"

},

"bar": {

"map": "(function(doc){if(doc.date && doc.title) {emit(doc.date, doc.title);})"

}

}

}

Why does it return an:

Expression does not eval to a function. ((new String("(function(doc){if(doc.date && doc.title) {emit(doc.date, doc.title);})")))

网友答案:

I know this question is old and the answer is actually in the comments of the question, but it seems like there should be a posted answer.

The final curly brace of the function is missing. Indented, it looks like the following:

function(doc) {
  if (doc.date && doc.title) {
    emit(doc.date, doc.title);
  }
}

Notice the two braces at the end in the one line version:

function(doc){if(doc.date && doc.title){emit(doc.date, doc.title);}}

I prefer to indent and uses spaces, so I don't miss those things.

分享给朋友:
您可能感兴趣的文章:
随机阅读: