Search.../

descending( )

Developer Preview

Adds a sort to a query, sorting by the specified properties in descending order.

Description

The descending() function refines a DiscountRulesQueryBuilder to sort by the value of propertyName in descending order. You can specify multiple properties for sorting in descending order by passing each property name as an additional argument. descending() sorts the results in the order the properties are passed. You can sort the following types:

  • Number: Sorts numerically.
  • Date: Sorts by date and time.
  • String: Sorts lexicographically, so 'abc' comes after 'XYZ'.

If a property contains a number stored as a string (for example, '0'), that value is sorted alphabetically and not numerically. If a property doesn't have a value, that value is ranked lowest.

Syntax

function descending(propertyNames: Array<string>): DiscountRulesQueryBuilder

descending Parameters

NAME
TYPE
DESCRIPTION
propertyNames
Optional
Array<
string
>

Properties used in the sort. To sort by multiple properties, pass properties as additional arguments.

Returns

Was this helpful?

Add a descending sort to a query

Copy Code
1const query = discountRules.queryDiscountRules.descending('_id');
2
Create a query, add a descending sort, and run it

Copy Code
1import { discountRules } from 'wix-ecom-backend';
2
3export async function myQueryFunction() {
4 const results = await discountRules
5 .queryDiscountRules()
6 .descending('_id')
7 .find();
8
9 if (results.items.length > 0) {
10 const items = results.items;
11 const firstItem = items[0];
12 const pageSize = results.pageSize;
13 const hasNext = results.hasNext();
14 const hasPrev = results.hasPrev();
15 const length = results.length;
16 const query = results.query;
17
18 return items;
19 } else {
20 // Handle if no matching items found
21 }
22}
23