CodeAPI

WixDataFilter

Provides functionality for filtering a query.

Table of Contents

FUNCTIONS

?
Perform actions on an object.
and( )Adds an and condition to the query or filter.
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.

and( )

Adds an and condition to the query or filter.

Description

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

Note that when chaining multiple WixDataFilter functions to a query an add condition is assumed. In such cases, you do not need to add a call to the and() function. For example, this query returns results where status is active and age is greater than 25.

 wixData.query("myCollection")
   .eq("status", "active")
   .gt("age", 25);

The and() function, is needed when perfoming compound queries. For example, the final query in this set of queries returns results where status is either pending or rejected and age is either less than 25 or greater than 65.

 let statusQuery = wixData.query("myCollection")
   .eq("status", "pending")
   .or(
     wixData.query("myCollection")
       .eq("status", "rejected")
   );

 let ageQuery = wixData.query("myCollection")
   .lt("age", 25)
   .or(
     wixData.query("myCollection")
       .gt("age", 65)
   );

 let statusAndAgeQuery = statusQuery.and(ageQuery);

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

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

Syntax

function and(query: WixDataQuery): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
query
A query to add to the initial query as an and condition.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an and to a query

let newQuery = query1.and(query2);

Create a query, add an or, and run it

import wixData from 'wix-data';

// ...

let statusQuery = wixData.query("myCollection")
  .eq("status", "pending")
  .or(
    wixData.query("myCollection")
      .eq("status", "rejected")
  );

let ageQuery = wixData.query("myCollection")
  .lt("age", 25)
  .or(
    wixData.query("myCollection")
      .gt("age", 65)
  );

statusQuery.and(ageQuery)
  .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
   */

between( )

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

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 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 lexicographically, so
    • "A" and "M" are between "A" and "Z", but "a", "m", "z" and "Z" are not.
    • "A", "M", "Z", "a", and "z" are between "A" and "z", but "z" is not.

Syntax

function between(propertyName: string, rangeStart: string | number | Date, rangeEnd: string | number | Date): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
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
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a between filter to a query

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

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

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

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( )

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

Description

The contains() function refines a WixDataQuery or WixDataFilter to only match items where the value of the specified property contains the specified string. Matching with contains() is not case sensitve, so "text" does contain "Tex".

You can use contains() with a property whose value is a String or a Reference. For properties of type reference it is recommended that you use the eq() function instead of contains(). With properties that are References, contains() matches by the ID of the referenced item as a String.

Syntax

function contains(propertyName: string, string: string): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
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
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a contains filter to a query

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

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

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

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( )

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

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. Matching with endsWith() is not case sensitve, so "TEXT" ends with "ext".

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.

Syntax

function endsWith(propertyName: string, string: string): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
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
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an ends with filter to a query

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

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

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

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( )

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

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.

Matching strings with eq() is case sensitve, so "text" is not equal to "Text".

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.

Syntax

function eq(propertyName: string, value: *): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
*
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an equals filter to a query

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

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

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

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( )

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

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 lexicographically, so "abc" and is greater than or equal to "ABC" (because of the greater than), but "ABC" is not greater than or equal to "abc".
  • Reference: Compares by the ID of the referenced item as a String.

Syntax

function ge(propertyName: string, value: string | number | Date): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a greater than or equals filter to a query

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

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

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

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( )

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

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 lexicographically, so "text" is greater than "Text".
  • Reference: Compares by the ID of the referenced item as a String.

Syntax

function gt(propertyName: string, value: string | number | Date): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object with the query definition, based on the supplied parameters.

Examples

Add a greater than filter to a query

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

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

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

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( )

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

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.

Matching strings with hasAll() is case sensitve, so "text" is not equal to "Text".

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.

Syntax

function hasAll(propertyName: string, value: string | number | Date | Array): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date | Array
The values to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a has all filter to a query

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

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

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( )

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

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.

Matching strings with hasSome() is case sensitve, so "text" is not equal to "Text".

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.

Syntax

function hasSome(propertyName: string, value: string | number | Date | Array): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date | Array
The values to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a has some filter to a query

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

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

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.

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( )

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

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.

Syntax

function isEmpty(propertyName: string): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The the property in which to check for a value.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an isEmpty filter to a query

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

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

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

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( )

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

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.

Syntax

function isNotEmpty(propertyName: string): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property in which to check for a value.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an isNotEmpty filter to a query

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

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

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

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( )

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

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 lexicographically, so "ABC" and is less than or equal to "abc" (because of the less than), but "abc" is not less than or equal to "ABC".
  • Reference: Compares by the ID of the referenced item as a String.

Syntax

function le(propertyName: string, value: string | number | Date): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a less than or equals filter to a query

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

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

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

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( )

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

Description

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

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

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

The following types of properties can be compared:

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

Syntax

function lt(propertyName: string, value: string | number | Date): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
string | number | Date
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object with the query definition, based on the supplied parameters.

Examples

Add a less than filter to a query

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

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

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

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( )

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

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.

Matching strings with ne() is case sensitve, so "text" is not equal to "Text".

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.

Syntax

function ne(propertyName: string, value: any): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
propertyName
string
The property whose value will be compared with value.
value
any
The value to match against.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a not equals filter to a query

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

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

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

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( )

Adds a not condition to the query or filter.

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.

Syntax

function not(query: WixDataQuery): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
query
A query to add to the initial query as a not condition.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a not to a query

let newQuery = query1.not(query2);

Create a query, add a not, and run it

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( )

Adds an or condition to the query or filter.

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 collections used by both the initial query and the query passed to the or function must be the same.

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

Syntax

function or(query: WixDataQuery): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
query
A query to add to the initial query as an or condition.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add an or to a query

let newQuery = query1.or(query2);

Create a query, add an or, and run it

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( )

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

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. Matching with startsWith() is not case sensitve, so "TEXT" starts with "tex".

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.

Syntax

function startsWith(propertyName: string, string: string): WixDataQuery
PARAMETERS
?
The kind of data the property stores.
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
?
Value that a function evaluates to when it is finished running.
A WixDataQuery object representing the refined query.

Examples

Add a starts with filter to a query

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

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

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

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