Search.../

lt( )

Refines a query or filter to match items whose specified property value is less than the specified value.

Description

The lt() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is less than the specified value.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "Text" is less than "text".
  • Reference: Compares by the ID of the referenced item as a String.

Syntax

function lt(propertyName: string, value: string | number | Date): WixDataQuery

lt Parameters

NAME
TYPE
DESCRIPTION
propertyName

string

The property whose value will be compared with value.

value

string | number | Date

The value to match against.

Returns

A WixDataQuery object with the query definition, based on the supplied parameters.

Return Type:

Was this helpful?

Add a less than filter to a query

Code Example

Copy Code
1let newQuery = query.lt("age", 25);
Create a query, add a less than filter, and run it

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6 .lt("age", 25)
7 .find()
8 .then( (results) => {
9 if(results.items.length > 0) {
10 let items = results.items;
11 let firstItem = items[0];
12 let totalCount = results.totalCount;
13 let pageSize = results.pageSize;
14 let currentPage = results.currentPage;
15 let totalPages = results.totalPages;
16 let hasNext = results.hasNext();
17 let hasPrev = results.hasPrev();
18 let length = results.length;
19 let query = results.query;
20 } else {
21 // handle case where no matching items found
22 }
23 } )
24 .catch( (error) => {
25 let errorMsg = error.message;
26 let code = error.code;
27 } );
Create a query, add a less than filter, and run it

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.query("myCollection")
6 .lt("age", 25)
7 .eq("status", "active")
8 .ascending("last_name", "first_name")
9 .limit(10)
10 .find()
11 .then( (results) => {
12 if(results.items.length > 0) {
13 let items = results.items;
14 let firstItem = items[0];
15 let totalCount = results.totalCount;
16 let pageSize = results.pageSize;
17 let currentPage = results.currentPage;
18 let totalPages = results.totalPages;
19 let hasNext = results.hasNext();
20 let hasPrev = results.hasPrev();
21 let length = results.length;
22 let query = results.query;
23 } else {
24 // handle case where no matching items found
25 }
26 } )
27 .catch( (error) => {
28 let errorMsg = error.message;
29 let code = error.code;
30 } );