wix-data.WixDataFilter

wix-data.WixDataFilter

Provides functionality for filtering a query.

Contents

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.
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.
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.
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.
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.
startsWith( ) Refines a query or filter to match items whose specified property value starts with a specified string.
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 properties 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;
  } );
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;
  } );
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 properties 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 properties 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 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.

If the specified property contains multiple references, pass item IDs in the value property. In such a case, hasSome() will match if any of the multiple references match any of the specified ID 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 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;
  } );

Add a has some filter on a multiple reference field to a query

This example gets the items from the movies collection that have a reference in the authors field to an item with an ID that is either 1357 or 2468.

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

// ...

wixData.query("movies")
  .hasSome("actors", ["1357", "2468"])
  .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;
  } );
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 the property in which 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 property in which 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 properties 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;
  } );
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 properties 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.

The query or filter passed to the or function must query or filter the same collection as the query or filter the or function is called on.

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
   */
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;
  } );