sort #
Sorts and returns elements contained in a list, a set of unique values or a sorted set.
By default, sorting is numeric and elements are compared by their value, interpreted as double precision floating point number.
Arguments #
sort(key, [options]);
Arguments | Type | Description |
---|---|---|
key | string | List, set or sorted set key |
options | object | Optional query arguments |
options #
The options
arguments can contain the following option properties:
Property | Type (default) | Description |
---|---|---|
alpha | boolean (false) | Performs an alphanumerical sort instead of a numeric one |
by | string | Instead of sorting by values, sorts by values contained in external keys, using the provided pattern completed by values of the list/set/sorted set to sort |
direction | string ('ASC') | Sorts in ascendant or descendant order. Allowed values: ASC , DESC |
get | string[] | Instead of returning the sorted values directly, returns the values contained in external keys, using patterns completed by the sorted values |
limit | integer[] | Limits the result set to a range of matching elements (similar to SELECT LIMIT offset, count in SQL). Format: [<offset(int)>, <count(int)>] |
queuable | boolean (true) | If true , queues the request during downtime, until connected to Kuzzle again |
timeout | number ( -1 ) | Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely |
triggerEvents | boolean ( false ) | If set to true , will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop. Available since Kuzzle 2.31.0 |
Resolve #
Resolves to the sorted elements.
Usage #
try {
await kuzzle.ms.sadd('setfoo', [1, 2, 3, 4, 5, 6, 7]);
await kuzzle.ms.rpush('listfoo', ['foo', 'bar', 'baz', 'qux']);
// Prints: [ '7', '6', '5', '4', '3', '2', '1' ]
console.log(await kuzzle.ms.sort('setfoo', {direction: 'DESC'}));
// Prints: [ 'bar', 'baz', 'foo', 'qux' ]
console.log(await kuzzle.ms.sort('listfoo', {alpha: true}));
} catch (error) {
console.error(error.message);
}
Edit this page on Github(opens new window)