All view results are automatically output sorted, with the sorting based on the content of the key in the output view. Views are sorted using a specific sortinf format, with the basic order for all basic and compound follows as follows:
Text (case sensitive, lowercase first, UTF-8 order)
Arrays (according to the values of each element, in order)
Objects (according to the values of keys, in key order)
The natural sorting is therefore by default close to natural sorting order both alphabetically (A-Z) and numerically (0-9).
There is no collation or foreign language support. Sorting is always according to the above rules based on UTF-8 values.
You can alter the direction of the sorting (reverse, highest to
lowest numerically, Z-A alphabetically) by using the
descending option. When set to true, this
reverses the order of the view results, ordered by their key.
Because selection is made after sorting the view results, if you
configure the results to be sorted in descending order and you
are selecting information using a key range, then you must also
endkey parameters. For example, if you query
ingredients where the start key is 'tomato' and the end key is
'zucchini', for example:
The selection will operate, returning information when the first key matches 'tomato' and stopping on the last key that matches 'zucchini'.
If the return order is reversed:
The query will return only entries matching 'tomato'. This is because the order will be reversed, 'zucchini' will appear first, and it is only when the results contain 'tomato' that any information is returned.
To get all the entries that match, the
endkey values must also be reversed:
The above selection will start generating results when 'zucchini' is identified in the key, and stop returning results when 'tomato' is identified in the key.
View output and selection are case sensitive. Specifying the key 'Apple' will not return 'apple' or 'APPLE' or other case differences. Normalizing the view output and query input to all lowercase or upper case will simplify the process by eliminating the case differences.