What JavaScript functions are available in the CouchDB map and reduce view functions?

烂漫一生 提交于 2019-12-23 16:11:40

问题


When writing map and reduce view functions for CouchDB in JavaScript, what are the build-in functions available?

For example, various examples refer to the following 2 functions: emit(key, value) and sum(values). Are there other functions like avg(values) available?

Where can I find a full list of all functions available?


回答1:


I don't know the CouchDB internals, however, from reading the sources, it looks like the map functions are evaluated in the sandbox created by init_sandbox(). So the available "global" functions are the ones you see added to it. For example:

  • require()
  • log()
  • isArray()
  • sum()
  • ...

_sum and _count, instead, are built-in reduce functions written in Erlang, and you can only use them as-is.




回答2:


Well first: not CacheDB but CouchDB (header). Second: these are not built-in Javascript functions - these are just built-in functions which work in Erlang. As far as i know there are only _sum and _count functions available.



来源:https://stackoverflow.com/questions/8076433/what-javascript-functions-are-available-in-the-couchdb-map-and-reduce-view-funct

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