1

As I know, CouchDB allows to use some integrated Erlang functions like a sort (and something else).

Doing text trimming in JS again, I thought: what if Couch already built this feature in? Maybe trim also integrated? And how much functions are ready to use?

If they are already done in Erlang, why I must use slow JS-versions?

So, that's my question: where I can find full list of available from JS functions for Couch?


Conclusion: it only a few of functions available and there's no trim. You can test your luck by writing your own functions at couch_query_server.erl and then rebuilding Couch from source.

Arman Hayots
  • 2,459
  • 6
  • 29
  • 53
  • You want to know the list of Erlang functions (standard library) which can be used inside *CouchDB Erlang View*? If so, just take a look at their official documentation such as [string](http://www.erlang.org/doc/man/string.html) and so on. – Hamidreza Soleimani Jan 11 '16 at 13:36
  • Not Erlang View, but JS views, handlers and anything at all. – Arman Hayots Jan 11 '16 at 13:37

1 Answers1

2

CouchDB has three built-in reduce functions. These are implemented in Erlang and run right inside CouchDB, so they are much faster than the equivalent JavaScript functions.

They are _count, _sum and _stats. You can find more details and examples here. They are implemented in couch_query_server.erl file.

Also you can use built-in Erlang functions and features with writing Native Erlang Query Server. But notice that it is disabled by default.

An example from CouchDB documentation for implementing a native Erlang query server:

%% Map Function
fun({Doc}) ->
  <<K,_/binary>> = proplists:get_value(<<"_rev">>, Doc, null),
  V = proplists:get_value(<<"_id">>, Doc, null),
  Emit(<<K>>, V)
end.

%% Reduce Function
fun(Keys, Values, ReReduce) -> erlang:length(Values) end.

It uses proplists:get_value/3 and erlang:length/1 MFAs (Module Function Arity) which are in Erlang standard library.

Edit: This thread can be a possible duplicate which seems to be outdated.

Community
  • 1
  • 1
Hamidreza Soleimani
  • 2,504
  • 16
  • 19