Search.../

startsWith( )

Developer Preview

Refines a query to match items where the specified property starts with the specified value.

Description

The startsWith() function refines a DiscountRulesQueryBuilder to match only items where the value of the specified propertyName starts with the specified string. Matching with startsWith() is case-sensitive, so 'TEXT' doesn't start with 'text'. You can only use startsWith() with a property whose value is a string.

Syntax

function startsWith(propertyName: string, value: string): DiscountRulesQueryBuilder

startsWith Parameters

NAME
TYPE
DESCRIPTION
propertyName
Optional
string

Property whose value is compared with string.

value
Optional
string

Returns

Was this helpful?

Add a startsWith filter to a query

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

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