问题
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