wix-data.WixDataQuery

wix-data.WixDataQuery

Contains functionality for refining a data query.

The WixDataQuery functions enable you to run, sort, filter, and controls which results a query returns.

Typically, you build a query using the query() function, refine the query by chaining WixDataQuery functions, and then execute the query by chaining the find() or count() functions.

For example, the following code queries a collection for all male customers over the age of 20 and logs the first 15 results to the console, sorted in ascending order by name:

IGltcG9ydCB3aXhEYXRhIGZyb20gJ3dpeC1kYXRhJzsKCiB3aXhEYXRhLnF1ZXJ5KCJDdXN0b21lciIpCiAgIC5ndCgiYWdlIiwgMjApCiAgIC5hc2NlbmRpbmcoIm5hbWUiKQogICAubGltaXQoMTUpCiAgIC5maW5kKCkKICAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICAgY29uc29sZS5sb2cocmVzdWx0cy5pdGVtcyk7CiAgIH0gKTs=
 import wixData from 'wix-data';

 wixData.query("Customer")
   .gt("age", 20)
   .ascending("name")
   .limit(15)
   .find()
   .then( (results) => {
     console.log(results.items);
   } );

Contents

ascending( ) Adds a sort to a query or sort, sorting by the specified properties in ascending order.
between( ) Refines a query or filter to match items whose specified property value is within a specified range.
contains( ) Refines a query or filter to match items whose specified property value contains a specified string.
count( ) Returns the number of items that match the query.
descending( ) Adds a sort to a query or sort, sorting by the specified properties in descending order.
endsWith( ) Refines a query or filter to match items whose specified property value ends with a specified string.
eq( ) Refines a query or filter to match items whose specified property value equals the specified value.
find( ) Returns the items that match the query.
ge( ) Refines a query or filter to match items whose specified property value is greater than or equal to the specified value.
gt( ) Refines a query or filter to match items whose specified property value is greater than the specified value.
hasAll( ) Refines a query or filter to match items whose specified property values equals all of the specified value parameters.
hasSome( ) Refines a query or filter to match items whose specified property value equals any of the specified value parameters.
include( ) Includes referenced items for the specified properties in a query's results.
isEmpty( ) Refines a query or filter to match items whose specified property does not exist or does not have any value.
isNotEmpty( ) Refines a query or filter to match items whose specified property has any value.
le( ) Refines a query or filter to match items whose specified property value is less than or equal to the specified value.
limit( ) Limits the number of items the query returns.
lt( ) Refines a query or filter to match items whose specified property value is less than the specified value.
ne( ) Refines a query or filter to match items whose specified property value does not equal the specified value.
not( ) Adds a not condition to the query or filter.
or( ) Adds an or condition to the query or filter.
skip( ) Sets the number of items to skip before returning query results.
startsWith( ) Refines a query or filter to match items whose specified property value starts with a specified string.
ascending( )

ascending( )

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

function ascending(...propertyName: String): WixDataQuery

Description

The ascending() function refines a WixDataQuery or WixDataSort to sort in ascending order of the specified properties. If you specify more than one property, ascending() sorts the results in ascending order by each property in the order they are listed.

You can sort the following types:

  • Number: Sorts numerically.
  • Date: Sorts by date and time.
  • String: Sorts alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

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

Parameters

propertyName (1 or more) String The properties that will be used in the sort.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an ascending sort to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpOwo=
let newQuery = query.ascending("last_name", "first_name");

Create a query, add an ascending sort, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5hc2NlbmRpbmcoImxhc3RfbmFtZSIsICJmaXJzdF9uYW1lIikKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ascending("last_name", "first_name")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an ascending sort, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5hc2NlbmRpbmcoImxhc3RfbmFtZSIsICJmaXJzdF9uYW1lIikKICAuZXEoInN0YXR1cyIsICJhY3RpdmUiKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ascending("last_name", "first_name")
  .eq("status", "active")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
between( )

between( )

Refines a query or filter to match items whose specified property value is within a specified range.

function between(propertyName: string, rangeStart: string|number|date,
  rangeEnd: string|number|date): WixDataQuery

Description

The between() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater than or equal to rangeStart and less than or equal to rangeEnd.

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 items can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.

Parameters

propertyName String The property whose value will be compared with rangeStart and rangeEnd.
rangeStart String |
Number |
Date
The beginning value of the range to match against.
rangeEnd String |
Number |
Date
The ending value of the range to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a between filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuYmV0d2VlbigiYWdlIiwgMjUsIDY1KTsK
let newQuery = query.between("age", 25, 65);

Create a query, add a between filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5iZXR3ZWVuKCJhZ2UiLCAyNSwgNjUpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .between("age", 25, 65)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a between filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5iZXR3ZWVuKCJhZ2UiLCAyNSwgNjUpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .between("age", 25, 65)
  .eq("status", "active")
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
contains( )

contains( )

Refines a query or filter to match items whose specified property value contains a specified string.

function contains(propertyName: string, string: string): WixDataQuery

Description

The contains() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property contains the specified string.

You can only use contains() with a property whose value is a String or Reference. When using a Reference, contains() matches by the ID of the referenced item as Strings.

Parameters

propertyName String The property whose value will be compared with the string.
string String The string to look for inside the specified property value.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a contains filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuY29udGFpbnMoImRlc2NyaXB0aW9uIiwgInNvbWUgd29yZHMiKTsK
let newQuery = query.contains("description", "some words");

Create a query, add a contains filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5jb250YWlucygiZGVzY3JpcHRpb24iLCAic29tZSB3b3JkcyIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .contains("description", "some words")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a contains filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5jb250YWlucygiZGVzY3JpcHRpb24iLCAic29tZSB3b3JkcyIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .contains("description", "some words")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
count( )

count( )

Returns the number of items that match the query.

function count([options: WixDataOptions]): Promise<Number>

Description

The count() function returns a Promise that resolves to the number of items that match the query. The Promise is rejected if count() is called with incorrect permissions or if any of the functions used to refine the query is invalid.

Calling the count() function triggers the beforeCount() and afterCount() hooks if they have been defined.

Use the options parameter to run count() without checking for permissions or without its registered hooks.

Any function that does not filter query results (e.g., ascending()) does not affect the result of count().

If you build a query and don't refine it with any WixDataQuery functions, count() returns the total number of items in the collection.

If you have already run a query with find(), you can retrieve the number of query results without calling count(). The find() function returns a Promise that resolves to a WixDataQueryResult object, which has a totalCount property whose value is the number of results.

Parameters

options (optional) WixDataOptions An object with one or both of the following boolean properties: suppressAuth, suppressHooks.

Return Value

Returns a Promise

On fulfillment Number The number of items that match the query.
On rejection Error The errors that caused the rejection.

Examples

Perform a count on a query

cXVlcnkuY291bnQoKQogIC50aGVuKCAobnVtKSA9PiB7CiAgICBsZXQgbnVtYmVyT2ZJdGVtcyA9IG51bTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
query.count()
  .then( (num) => {
    let numberOfItems = num;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query and perfom a count on it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5jb3VudCgpCiAgLnRoZW4oIChudW0pID0+IHsKICAgIGxldCBudW1iZXJPZkl0ZW1zID0gbnVtOwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .count()
  .then( (num) => {
    let numberOfItems = num;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query and perfom a count on it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuY291bnQoKQogIC50aGVuKCAobnVtKSA9PiB7CiAgICBsZXQgbnVtYmVyT2ZJdGVtcyA9IG51bTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .gt("age", 25)
  .count()
  .then( (num) => {
    let numberOfItems = num;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
descending( )

descending( )

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

function descending(...propertyName: String): WixDataQuery

Description

The descending() function refines a WixDataQuery or WixDataSort to sort in descending order of the specified properties. If you specify more than one property, descending() sorts the results in descending order by each property in the order they are listed.

You can sort the following types:

  • Number: Sorts numerically.
  • Date: Sorts by date and time.
  • String: Sorts alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

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

Parameters

propertyName (1 or more) String The properties that will be used in the sort.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an descending sort to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuZGVzY2VuZGluZygibGFzdF9uYW1lIiwgImZpcnN0X25hbWUiKTsK
let newQuery = query.descending("last_name", "first_name");

Create a query, add an descending sort, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5kZXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .descending("last_name", "first_name")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an descending sort, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5kZXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAubGltaXQoMTApCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .descending("last_name", "first_name")
  .eq("status", "active")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
endsWith( )

endsWith( )

Refines a query or filter to match items whose specified property value ends with a specified string.

function endsWith(propertyName: string, string: string): WixDataQuery

Description

The endsWith() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property ends with the specified string.

You can only use endsWith() with a property whose value is a String or Reference. When using a Reference, endsWith() matches by the ID of the referenced item as Strings.

Parameters

propertyName String The property whose value will be compared with the string.
string String The string to look for at the beginning of the specified property value.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an ends with filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuZW5kc1dpdGgoImxhc3RfbmFtZSIsICJ6Iik7Cg==
let newQuery = query.endsWith("last_name", "z");

Create a query, add an ends with filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lbmRzV2l0aCgibGFzdF9uYW1lIiwgInoiKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .endsWith("last_name", "z")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an ends with filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lbmRzV2l0aCgibGFzdF9uYW1lIiwgInoiKQogIC5ndCgiYWdlIiwgMjUpCiAgLmFzY2VuZGluZygibGFzdF9uYW1lIiwgImZpcnN0X25hbWUiKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .endsWith("last_name", "z")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
eq( )

eq( )

Refines a query or filter to match items whose specified property value equals the specified value.

function eq(propertyName: string, value: *): WixDataQuery

Description

The eq() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals 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 the value of the propertyName property is an Array, eq() includes items in which any of the elements of the Array match the specified value.

Parameters

propertyName String The property whose value will be compared with value.
value The value to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an equals filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuZXEoInN0YXR1cyIsICJhY3RpdmUiKTsK
let newQuery = query.eq("status", "active");

Create a query, add an equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
find( )

find( )

Returns the items that match the query.

function find([options: WixDataOptions]): Promise<WixDataQueryResult>

Description

The find() function returns a Promise that resolves to the results found by the query and some information about the results. The Promise is rejected if find() is called with incorrect permissions or if any of the functions used to refine the query is invalid.

Calling the find() function triggers the beforeQuery() and afterQuery() hooks if they have been defined. If the query being run contains an include(), calling find() triggers beforeQuery() and afterQuery() hooks for the referenced collection as well.

Use the options parameter to run find() without checking for permissions or without its registered hooks.

If you build a query and don't refine it with any wixDataQuery functions, find() returns the entire collection.

Parameters

options (optional) WixDataOptions An object with one or both of the following boolean properties: suppressAuth, suppressHooks.

Return Value

Returns a Promise

On fulfillment WixDataQueryResult A Promise that resolves to the results of the query.
On rejection Error Any errors that caused the query to fail, returned as an array.

Examples

Perform a find on a query

cXVlcnkuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
query.find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
ge( )

ge( )

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

function ge(propertyName: string, value: string|number|date): WixDataQuery

Description

The ge() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater than or equal to 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 items can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

Parameters

propertyName String The property whose value will be compared with value.
value String |
Number |
Date
The value to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a greater than or equals filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuZ2UoImFnZSIsIDI1KTsK
let newQuery = query.ge("age", 25);

Create a query, add a greater than or equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5nZSgiYWdlIiwgMjUpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ge("age", 25)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a greater than or equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5nZSgiYWdlIiwgMjUpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ge("age", 25)
  .eq("status", "active")
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
gt( )

gt( )

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

function gt(propertyName: string, value: string|number|date): WixDataQuery

Description

The gt() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is greater 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 items can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

Parameters

propertyName String The property whose value will be compared with value.
value String |
Number |
Date
The value to match against.

Return Value

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

Examples

Add a greater than filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuZ3QoImFnZSIsIDI1KTsK
let newQuery = query.gt("age", 25);

Create a query, add a greater than filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5ndCgiYWdlIiwgMjUpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .gt("age", 25)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a greater than filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5ndCgiYWdlIiwgMjUpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .gt("age", 25)
  .eq("status", "active")
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
hasAll( )

hasAll( )

Refines a query or filter to match items whose specified property values equals all of the specified value parameters.

function hasAll(propertyName: string, ...value: *): WixDataQuery

Description

The hasAll() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals all of the specified values.

If the value of the specified property is an array, hasAll() will match if there is a match in the elements of that array for all of the specified values.

You can specify a list of values to match by providing comma-separated String, Number, or Date types as the value parameters. You can also specify a list of these values by including them in an array and providing the array as the value.

Parameters

propertyName String The name of the property whose value will be compared with value.
value String |
Number |
Date |
Array
The values to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a has all filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaGFzQWxsKCJjb2xvcnMiLCBbInJlZCIsICJ5ZWxsb3ciLCAiYmx1ZSJdKTsKCi8vIG9yCgpsZXQgbmV3UXVlcnkgPSBxdWVyeS5oYXNBbGwoImNvbG9ycyIsICJyZWQiLCAieWVsbG93IiwgImJsdWUiKTsK
let newQuery = query.hasAll("colors", ["red", "yellow", "blue"]);

// or

let newQuery = query.hasAll("colors", "red", "yellow", "blue");

Create a query, add a has all filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5oYXNBbGwoImNvbG9ycyIsIFsicmVkIiwgInllbGxvdyIsICJibHVlIl0pCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .hasAll("colors", ["red", "yellow", "blue"])
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a has all filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5oYXNBbGwoImNvbG9ycyIsIFsicmVkIiwgInllbGxvdyIsICJibHVlIl0pCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .hasAll("colors", ["red", "yellow", "blue"])
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
hasSome( )

hasSome( )

Refines a query or filter to match items whose specified property value equals any of the specified value parameters.

function hasSome(propertyName: string, ...value: *): WixDataQuery

Description

The hasSome() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property equals any of the specified values.

If the value of the specified property is an array, hasSome() will match if any of the elements of that array match any of the specified values.

You can specify a list of values to match by providing comma-separated String, Number, or Date types as the value parameters. You can also specify a list of these values by including them in an array and providing the array as the value.

Parameters

propertyName String The name of the property whose value will be compared with value.
value String |
Number |
Date |
Array
The values to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a has some filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaGFzU29tZSgiY29sb3JzIiwgWyJyZWQiLCAieWVsbG93IiwgImJsdWUiXSk7CgovLyBvcgoKbGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaGFzU29tZSgiY29sb3JzIiwgInJlZCIsICJ5ZWxsb3ciLCAiYmx1ZSIpOwo=
let newQuery = query.hasSome("colors", ["red", "yellow", "blue"]);

// or

let newQuery = query.hasSome("colors", "red", "yellow", "blue");

Create a query, add a has some filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5oYXNTb21lKCJjb2xvcnMiLCBbInJlZCIsICJ5ZWxsb3ciLCAiYmx1ZSJdKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .hasSome("colors", ["red", "yellow", "blue"])
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a has some filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5oYXNTb21lKCJjb2xvcnMiLCBbInJlZCIsICJ5ZWxsb3ciLCAiYmx1ZSJdKQogIC5ndCgiYWdlIiwgMjUpCiAgLmFzY2VuZGluZygibGFzdF9uYW1lIiwgImZpcnN0X25hbWUiKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .hasSome("colors", ["red", "yellow", "blue"])
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
include( )

include( )

Includes referenced items for the specified properties in a query's results.

function include(...propertyName: String): WixDataQuery

Description

The include() function refines a query so that the items returned in the query's results include the full referenced items for the specified properties.

For example, suppose you have a books collection with an author field that references an authors collection. Querying the books collection with an include("author") will return the relevant book items and each item will include the full referenced author item in the book's author property.

Querying a collection that contains reference fields without using the include() function returns items that contain only the ID of the referenced item, and not the full referenced items.

Parameters

propertyName (1 or more) String The properties for which to include referenced items.

Return Value

WixDataQuery A WixDataQuery object representing the query.

Examples

Add an include to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaW5jbHVkZSgicmVmZXJlbmNlRmllbGQiKTsK
let newQuery = query.include("referenceField");

Create a query, include a reference field, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5pbmNsdWRlKCJyZWZlcmVuY2VGaWVsZCIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCBmaXJzdFJlZlByb3AgPSBmaXJzdEl0ZW0ucmVmZXJlbmNlRmllbGQucHJvcGVydHlOYW1lOwoKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .include("referenceField")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let firstRefProp = firstItem.referenceField.propertyName;

    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, include a reference field, and run it

In this example there is a books collection which has two reference fields that reference an authors collection and a publishers collection.

The query includes the author and publisher properties so that each returned book will also include the full items of its referenced author and publisher.

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJib29rcyIpCiAgLmluY2x1ZGUoImF1dGhvciIsICJwdWJsaXNoZXIiKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBib29rcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RCb29rID0gaXRlbXNbMF07CiAgICBsZXQgZmlyc3RBdXRob3IgPSBmaXJzdEJvb2suYXV0aG9yOwogICAgbGV0IGZpcnN0QXV0aG9yQmlvID0gZmlyc3RBdXRob3IuYmlvOwogICAgbGV0IGZpcnN0UHVibGlzaGVyID0gZmlyc3RCb29rLnB1Ymxpc2hlci5uYW1lOwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("books")
  .include("author", "publisher")
  .find()
  .then( (results) => {
    let books = results.items;
    let firstBook = items[0];
    let firstAuthor = firstBook.author;
    let firstAuthorBio = firstAuthor.bio;
    let firstPublisher = firstBook.publisher.name;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, include a reference field, and run it

In this example there is a books collection which as two reference fields that reference an authors collection and a publishers collection.

The query is refined to only include books from a specific publisher using the eq() function and the publisher's ID.

The query also includes the author property so that each returned book will include the full item of its referenced author.

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJib29rcyIpCiAgLmVxKCJwdWJsaXNoZXIiLCAiMDAwMDEiKQogIC5pbmNsdWRlKCJhdXRob3IiKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBib29rcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RCb29rID0gaXRlbXNbMF07CiAgICBsZXQgZmlyc3RBdXRob3IgPSBmaXJzdEJvb2suYXV0aG9yOwogICAgbGV0IGZpcnN0QXV0aG9yQmlvID0gZmlyc3RBdXRob3IuYmlvOwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("books")
  .eq("publisher", "00001")
  .include("author")
  .find()
  .then( (results) => {
    let books = results.items;
    let firstBook = items[0];
    let firstAuthor = firstBook.author;
    let firstAuthorBio = firstAuthor.bio;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
isEmpty( )

isEmpty( )

Refines a query or filter to match items whose specified property does not exist or does not have any value.

function isEmpty(propertyName: string): WixDataQuery

Description

The isEmpty() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is null or undefined or the property does not exist.

If the property contains any value at all for a given item, including the empty string or an invalid value, that item will match the query.

Parameters

propertyName String The name of the property to check for a value.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an isEmpty filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaXNFbXB0eSgiYmlvIik7Cg==
let newQuery = query.isEmpty("bio");

Create a query, add an isEmpty filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5pc0VtcHR5KCJiaW8iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .isEmpty("bio")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an isEmpty filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5pc0VtcHR5KCJiaW8iKQogIC5ndCgiYWdlIiwgMjUpCiAgLmFzY2VuZGluZygibGFzdF9uYW1lIiwgImZpcnN0X25hbWUiKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .isEmpty("bio")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
isNotEmpty( )

isNotEmpty( )

Refines a query or filter to match items whose specified property has any value.

function isNotEmpty(propertyName: string): WixDataQuery

Description

The isNotEmpty() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is not null or undefined.

If the property contains any value at all for a given item, including the empty string or an invalid value, that item will match the query.

Parameters

propertyName String The name of the property to check for a value.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an isNotEmpty filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuaXNOb3RFbXB0eSgiYmlvIik7Cg==
let newQuery = query.isNotEmpty("bio");

Create a query, add an isNotEmpty filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5pc05vdEVtcHR5KCJiaW8iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .isNotEmpty("bio")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add an isNotEmpty filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5pc05vdEVtcHR5KCJiaW8iKQogIC5ndCgiYWdlIiwgMjUpCiAgLmFzY2VuZGluZygibGFzdF9uYW1lIiwgImZpcnN0X25hbWUiKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .isNotEmpty("bio")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
le( )

le( )

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

function le(propertyName: string, value: string|number|date): WixDataQuery

Description

The le() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property is less than or equal to 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 items can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

Parameters

propertyName String The property whose value will be compared with value.
value String |
Number |
Date
The value to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a less than or equals filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkubGUoImFnZSIsIDI1KTsK
let newQuery = query.le("age", 25);

Create a query, add a less than or equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5sZSgiYWdlIiwgMjUpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .le("age", 25)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a less than or equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5sZSgiYWdlIiwgMjUpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .le("age", 25)
  .eq("status", "active")
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
limit( )

limit( )

Limits the number of items the query returns.

function limit(limit: Number): WixDataQuery

Description

The limit function defines the number of results a query returns in each page. Only one page of results is retreived at a time. The next() and prev() functions are used to navigate the pages of a query result.

By default, limit is set to 50.

The maximum value that limit() can accept is 1000.

Parameters

limit Number The number of items to return, which is also the pageSize of the results object.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a limit to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkubGltaXQoMTApOwo=
let newQuery = query.limit(10);

Create a query, add a limit, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5saW1pdCgxMCkKICAuZmluZCgpCiAgLnRoZW4oIChyZXN1bHRzKSA9PiB7CiAgICBsZXQgaXRlbXMgPSByZXN1bHRzLml0ZW1zOwogICAgbGV0IGZpcnN0SXRlbSA9IGl0ZW1zWzBdOwogICAgbGV0IHRvdGFsQ291bnQgPSByZXN1bHRzLnRvdGFsQ291bnQ7CiAgICBsZXQgcGFnZVNpemUgPSByZXN1bHRzLnBhZ2VTaXplOwogICAgbGV0IGN1cnJlbnRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsKICAgIGxldCB0b3RhbFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOwogICAgbGV0IGhhc05leHQgPSByZXN1bHRzLmhhc05leHQoKTsKICAgIGxldCBoYXNQcmV2ID0gcmVzdWx0cy5oYXNQcmV2KCk7CiAgICBsZXQgbGVuZ3RoID0gcmVzdWx0cy5sZW5ndGg7CiAgICBsZXQgcXVlcnkgPSByZXN1bHRzLnF1ZXJ5OwogIH0gKQogIC5jYXRjaCggKGVycm9yKSA9PiB7CiAgICBsZXQgZXJyb3JNc2cgPSBlcnJvci5tZXNzYWdlOwogICAgbGV0IGNvZGUgPSBlcnJvci5jb2RlOwogIH0gKTsK
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a limit, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
lt( )

lt( )

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

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

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 items can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares alphabetically. The sort is based on the JavaScript sort methodology, which is a lexicographical sort that compares Unicode characters by their code points.
  • Reference: Compares by the ID of the referenced item as a String.

Parameters

propertyName String The property whose value will be compared with value.
value String |
Number |
Date
The value to match against.

Return Value

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

Examples

Add a less than filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkubHQoImFnZSIsIDI1KTsK
let newQuery = query.lt("age", 25);

Create a query, add a less than filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5sdCgiYWdlIiwgMjUpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .lt("age", 25)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a less than filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5sdCgiYWdlIiwgMjUpCiAgLmVxKCJzdGF0dXMiLCAiYWN0aXZlIikKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .lt("age", 25)
  .eq("status", "active")
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
ne( )

ne( )

Refines a query or filter to match items whose specified property value does not equal the specified value.

function ne(propertyName: string, value: *): WixDataQuery

Description

The ne() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property does not equal the specified value.

It only matches values of the same type. For example, a number value stored as a String type is considered not equal to the same number stored as a Number type.

If the value of the propertyName property is an Array, ne() includes items in which none of the elements of the Array match the specified value.

Parameters

propertyName String The property whose value will be compared with value.
value The value to match against.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a not equals filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkubmUoInN0YXR1cyIsICJhY3RpdmUiKTsK
let newQuery = query.ne("status", "active");

Create a query, add a not equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5uZSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ne("status", "active")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a not equals filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5uZSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ne("status", "active")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
not( )

not( )

Adds a not condition to the query or filter.

function not(query WixDataQuery): WixDataQuery

Description

The not() function adds a not condition to a WixDataQuery or WixDataFilter. A query or filter with a not returns all the items that match the query or filter as defined up to the not function, but don't match the query or filter passed to the not function.

If the query or filter only contains a not() function, it returns all the items that don't match the query defined by the not method.

The collections referenced by both the initial query and the query passed to the not function must be the same.

Parameters

query WixDataQuery A query to add to the initial query as a not condition.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a not to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkxLm5vdChxdWVyeTIpOwo=
let newQuery = query1.not(query2);

Create a query, add a not, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5ndCgiYWdlIiwgMjUpCiAgLm5vdCgKICAgIHdpeERhdGEucXVlcnkoIm15Q29sbGVjdGlvbiIpCiAgICAgIC5lcSgiYWNjZXNzX3R5cGUiLCAicmVzdHJpY3RlZCIpCiAgKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .gt("age", 25)
  .not(
    wixData.query("myCollection")
      .eq("access_type", "restricted")
  )
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
or( )

or( )

Adds an or condition to the query or filter.

function or(query WixDataQuery): WixDataQuery

Description

The or() function adds an inclusive or condition to a WixDataQuery or WixDataFilter. A query or filter with an or returns all the items that match the query or filter as defined up to the or function, the items that match the query or filter passed to the or function, and the items that match both.

If the query or filter only contains an or() function, it returns all the items in the collection.

The collections referenced by both the initial query and the query passed to the or function must be the same.

Parameters

query WixDataQuery A query to add to the initial query as an or condition.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add an or to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkxLm9yKHF1ZXJ5Mik7Cg==
let newQuery = query1.or(query2);

Create a query, add an or, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5sdCgiYWdlIiwgMjUpCiAgLm9yKAogICAgd2l4RGF0YS5xdWVyeSgibXlDb2xsZWN0aW9uIikKICAgICAgLmd0KCJhZ2UiLCA2NSkKICApCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7CgogIC8qCiAgICogRm9yIGV4YW1wbGUsIHJlc3VsdHMgY29udGFpbiBpdGVtcyB3aGVyZSBhZ2UgaXM6CiAgICogMTgKICAgKiAyMQogICAqIDY3CiAgICogOTAKICAgKgogICAqIEJ1dCBub3QgaXRlbXMgd2hlcmUgYWdlIGlzOgogICAqIDI1CiAgICogMzAKICAgKiA0MAogICAqIDY1CiAgICovCg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .lt("age", 25)
  .or(
    wixData.query("myCollection")
      .gt("age", 65)
  )
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

  /*
   * For example, results contain items where age is:
   * 18
   * 21
   * 67
   * 90
   *
   * But not items where age is:
   * 25
   * 30
   * 40
   * 65
   */
skip( )

skip( )

Sets the number of items to skip before returning query results.

function skip(skip: Number): WixDataQuery

Description

The skip() function defines the number of results to skip in the query results before returning new query results.

For example, if you query a collection and 50 items match your query, but you set skip to 10, the results returned will skip the first 10 items that match and return the 11th through 50th items.

By default, skip is set to 0.

Parameters

skip Number The number of items to skip in the query results before returning the results.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a skip to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuc2tpcCgxMCk7Cg==
let newQuery = query.skip(10);

Create a query, add a skip, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5za2lwKDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .skip(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a skip, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5lcSgic3RhdHVzIiwgImFjdGl2ZSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLnNraXAoMTApCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .eq("status", "active")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .skip(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );
startsWith( )

startsWith( )

Refines a query or filter to match items whose specified property value starts with a specified string.

function startsWith(propertyName: string, string: string): WixDataQuery

Description

The startsWith() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property starts with the defined string.

You can only use startsWith() with a property whose value is a String or Reference. When using a Reference, startsWith() matches by the ID of the referenced item as Strings.

Parameters

propertyName String The property whose value will be compared with the string.
string String The string to look for at the beginning of the specified property value.

Return Value

WixDataQuery A WixDataQuery object representing the refined query.

Examples

Add a starts with filter to a query

bGV0IG5ld1F1ZXJ5ID0gcXVlcnkuc3RhcnRzV2l0aCgibGFzdF9uYW1lIiwgIk0iKTsK
let newQuery = query.startsWith("last_name", "M");

Create a query, add a starts with filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5zdGFydHNXaXRoKCJsYXN0X25hbWUiLCAiTSIpCiAgLmZpbmQoKQogIC50aGVuKCAocmVzdWx0cykgPT4gewogICAgbGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKICAgIGxldCBmaXJzdEl0ZW0gPSBpdGVtc1swXTsKICAgIGxldCB0b3RhbENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OwogICAgbGV0IHBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsKICAgIGxldCBjdXJyZW50UGFnZSA9IHJlc3VsdHMuY3VycmVudFBhZ2U7CiAgICBsZXQgdG90YWxQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsKICAgIGxldCBoYXNOZXh0ID0gcmVzdWx0cy5oYXNOZXh0KCk7CiAgICBsZXQgaGFzUHJldiA9IHJlc3VsdHMuaGFzUHJldigpOwogICAgbGV0IGxlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOwogICAgbGV0IHF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsKICB9ICkKICAuY2F0Y2goIChlcnJvcikgPT4gewogICAgbGV0IGVycm9yTXNnID0gZXJyb3IubWVzc2FnZTsKICAgIGxldCBjb2RlID0gZXJyb3IuY29kZTsKICB9ICk7Cg==
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .startsWith("last_name", "M")
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Create a query, add a starts with filter, and run it

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5zdGFydHNXaXRoKCJsYXN0X25hbWUiLCAiTSIpCiAgLmd0KCJhZ2UiLCAyNSkKICAuYXNjZW5kaW5nKCJsYXN0X25hbWUiLCAiZmlyc3RfbmFtZSIpCiAgLmxpbWl0KDEwKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSByZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IHJlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSByZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSByZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .startsWith("last_name", "M")
  .gt("age", 25)
  .ascending("last_name", "first_name")
  .limit(10)
  .find()
  .then( (results) => {
    let items = results.items;
    let firstItem = items[0];
    let totalCount = results.totalCount;
    let pageSize = results.pageSize;
    let currentPage = results.currentPage;
    let totalPages = results.totalPages;
    let hasNext = results.hasNext();
    let hasPrev = results.hasPrev();
    let length = results.length;
    let query = results.query;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );