Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.
The "BuiltIn_Reduce_Functions" page has been changed by JensAlfke:
http://wiki.apache.org/couchdb/BuiltIn_Reduce_Functions?action=diff&rev1=5&rev2=6
Comment:
Grammatical cleanup
= BuiltIn Reduce Functions =
<<TableOfContents()>>
 Currently (CouchDB 0.11.0) there are three builtin reduce functions. Builtin reduce functions
are performed right inside CouchDB implemented in Erlang. In most cases it is very fast because
they are way more efficient.
+ CouchDB has three builtin reduce functions. These are implemented in Erlang and run right
inside CouchDB, so they are much faster than the equivalent JavaScript functions.
== Usage ==
 To use builtin reduce functions, you simply need to replace your reduce function with a
string containing {{{_count}}}, {{{_sum}}} or {{{_stats}}} (without any preceding or tailing
whitespace).
+ To use builtin reduce functions, you simply need to replace your reduce function with the
string {{{_count}}}, {{{_sum}}} or {{{_stats}}} (without any preceding or tailing whitespace).
 Here is an example design document using buildin reduce functions:
+ Here is an example design document using builtin reduce functions:
{{{
{
"_id":"_design/company",
@@ 30, +30 @@
}
}}}
 == Available BuildIn Functions ==
+ == Available BuiltIn Functions ==
=== _sum ===
 {{{_sum}}} just sums up the emitted values. Therefore the mapped values need to be numbers.
+ {{{_sum}}} just adds up the emitted values, which must be numbers.
The !JavaScript equivalent is:
{{{
@@ 44, +44 @@
=== _count ===
 {{{_count}}} counts the emitted values. It's like {{{_sum}}} for {{{emit(foo, 1)}}}. The
map function may emit anything you want.
+ {{{_count}}} counts the number of emitted values. (It's like {{{_sum}}} for {{{emit(foo,
1)}}}.) It ignores the contents of the values, so they can by any type.
The !JavaScript equivalent is:
{{{
function(keys, values, rereduce) {
if (rereduce) {
return sum(values);
 }
 else {
+ } else {
return values.length;
}
}
@@ 61, +60 @@
=== _stats ===
 {{{_stats}}} calculates various numerical statistics on your emitted data. {{{_stats}}}
requires, just like {{{_sum}}}, your emitted values to be numbers.
+ {{{_stats}}} calculates some numerical statistics on your emitted values, which must be
numbers.
 The reduce output looks like this:
+ The reduce output is an object that looks like this:
{{{
 {"update_seq":6,"rows":[
 {"key":null,"value":{"sum":2,"count":2,"min":1,"max":1,"sumsqr":2}}
+ {"sum":2,"count":2,"min":1,"max":1,"sumsqr":2}
 ]}
}}}
 {{{sum}}} and {{{count}}} is the equiverlent to {{{_sum}}} and {{{_count}}}. {{{min}}} and
{{{max}}} are the minimum and maximum values of the emitted values. {{{sumsqr}}} is the sum
over all squares of the emitted values (useful for statistics calculations).
+ {{{"sum"}}} and {{{"count"}}} are equivalent to the {{{_sum}}} and {{{_count}}} reductions.
{{{"min"}}} and {{{"max"}}} are the minimum and maximum emitted values. {{{"sumsqr"}}} is
the sum of the squares of the emitted values (useful for statistical calculations like standard
deviation).
