4
votes

As you know, the reduce function in CouchDB views looks like this:

function (key, values, rereduce) {
    return sum(values);
}

where the definition of first arguments is as follows:

when rereduce is false, then:

  1. key will be an array whose elements are arrays of the form [key,id], where key is a key emitted by the map function and id is that of the document from which the key was generated.
  2. values will be an array of the values emitted for the respective elements in keys.

My question is: when rereduce is false, are there any guarantees regarding the order of key (or values) array elements? My gut feel (based on Reduce vs Rereduce chapter) is that keys, and respectively values, should be ordered, but I do not see any direct confirmation.

Any ideas? Thank you!

1

1 Answers

-1
votes

From https://cloudant.com/for-developers/all_docs/

Sort Order

All indexes are sorted by their key. The sort order is:

null
false
true
numbers
text, cases sensitive - lower case first
arrays, sorted element by element
objects

The full specification is documented in the CouchDB Wiki.