Search:

Search all manuals
Search this manual
Manual
Couchbase Server Manual 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Developer Guide 2.0
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
9.8 Querying Views
Chapter Sections
Chapters

9.8.5. Ordering

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:

The natural sorting is therefore by default close to natural sorting order both alphabetically (A-Z) and numerically (0-9).

Note

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 reverse the startkey and endkey parameters. For example, if you query ingredients where the start key is 'tomato' and the end key is 'zucchini', for example:

?startkey="tomato"&endkey="zucchini"

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:

?descending=true&startkey="tomato"&endkey="zucchini"

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 startkey and endkey values must also be reversed:

?descending=true&startkey="zucchini"&endkey="tomato"

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.

Tip

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.