sort
Set the sort order of the cursor.
Syntax
let cursor = #db.f(query, projection)
cursor.sort(sort)
Parameters
sort
An object specifying the sort order, e.g. { n_hits: 1, n_fails: -1 } . Each key is the path of a sort key, each value specifies direction (1 for ascending, -1 for descending).
Note that the order of properties in the object directly affects the sort order:
The sort object { n_hits: 1, n_fails: -1 } sorts by n_hits ascending first, and only if two documents have identical n_hits values, sorts them by n_fails descending. The sort object { n_fails: -1, n_hits: 1 } does the opposite: it sorts by n_fails descending first, and only compares n_hits if n_fails on two documents is equal.
(In JavaScript, 'regular' properties are ordered by creation order, with the first created property appearing first. Keep this in mind when dynamically building sort objects.)
Return
Returns a new cursor object, with the same handle as the input cursor.
This can be used to chain into other methods.
Cursor State
This function keeps the cursor open.