couchdb: map in design document gives compilation_error

两盒软妹~` 提交于 2019-12-23 08:47:49

问题


I use Couchdb 1.1.1 in Debian testing

and I have this design document in database

{
 "_id": "_design/Page",
 "_rev": "9-1944cdebabf20ae569eab7b534b43e67",
 "views": {
     "all": {
         "map": "function(doc) {}"
     }
 },
 "language": "javascript"
}

but still I get in http://localhost:5984/db_development/_design/Page/_view/all

this {"error":"compilation_error","reason":"Expression does not eval to a function. ((new String(\"function(doc) {}\")))"}

I tried to run different simple map functions in spidermonkey-bin interpreter and they was loaded correctly, but same error in couchdb

I really can't see, where problem is....

Ok, in mailing list I found that it is needed to wrap function to parentheses "()", because something has changed in newer spidermonkey

So map function looks like this: "map": "(function(doc) { emit([doc._id, doc._rev]);})"


回答1:


Ok, in mailing list I found that it is needed to wrap function to parentheses "()", because something has changed in newer spidermonkey

So map function looks like this: "map": "(function(doc) { emit([doc._id, doc._rev]);})"




回答2:


If you get this error, be careful that the design doc is structured correctly. (I got a message like this because of a dumb error in my shows definition.)

Also, not sure this is a problem, but I don't think there should be a space before the curly brackets in the function definition.




回答3:


There is no return statement inside the map function. Your map function needs to return something.

If you need to get a raw dump of all documents, there is a built-in feature for that: http://wiki.apache.org/couchdb/HTTP_Document_API#all_docs



来源:https://stackoverflow.com/questions/9034284/couchdb-map-in-design-document-gives-compilation-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!