CodeAPI

WixDataQueryResult

The results of a data query, containing the retrieved items.

When you execute a query with the find() function, it returns a Promise that resolves to a WixDataQueryResult object. This object contains the items that match the query, information about the query itself, and functions for paging through the query results.

Table of Contents

PROPERTIES

?
Store values associated with an object.
currentPageReturns the index of the current results page number.
itemsReturns the items that match the query.
lengthReturns the number of items in the current results page.
pageSizeReturns the query page size.
partialIncludesIndicates if referenced items have been trimmed from the results.
queryReturns the query used to get the current results.
totalCountReturns the total number of items that match the query.
totalPagesReturns the total number of pages the query produced.

FUNCTIONS

?
Perform actions on an object.
hasNext( )Indicates if the query has more results.
hasPrev( )Indicates the query has previous results.
next( )Retrieves the next page of query results.
prev( )Retrieves the previous page of query results.

currentPage

Returns the index of the current results page number.

Description

The currentPage is a zero-based index of the current page of results.

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

The currentPage property returns undefined if the query returned no results.

Syntax

get currentPage(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the current page index of a query result

let resultPage = results.currentPage; // 0

Perform a query and get the current page index of the query result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultPage = results.currentPage; // 0
  } ) ;

items

Returns the items that match the query.

Description

The current page of items retrieved by the query.

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

Syntax

get items(): Array<Object>
TYPE
?
The kind of data the property stores.
Array<Object>

Examples

Get the items of a query result

let items = results.items;

/*
 * [
 *   {
 *     "_id":          "1234",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-29T08:35:52.344Z",
 *     "_updatedDate": "2017-05-29T08:35:52.344Z",
 *     "title":        "Dr.",
 *     "first_name":   "Jane",
 *     "last_name":    "Doe",
 *     "status":       "active"
 *   },
 *   {
 *     "_id":          "5678",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-25T12:48:56.572Z",
 *     "_updatedDate": "2017-05-29T07:30:15.869Z",
 *     "title":        "Mr.",
 *     "first_name":   "John",
 *     "last_name":    "Doe",
 *     "status":       "active"
 *   }
 * ]
 */

Perform a query and get the items of the result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let items = results.items; // see below
  } ) ;

/* items:
 *
 * [
 *   {
 *     "_id":          "1234",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-29T08:35:52.344Z",
 *     "_updatedDate": "2017-05-29T08:35:52.344Z",
 *     "title":        "Dr.",
 *     "first_name":   "Jane",
 *     "last_name":    "Doe",
 *     "status":       "active"
 *   },
 *   {
 *     "_id":          "5678",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-25T12:48:56.572Z",
 *     "_updatedDate": "2017-05-29T07:30:15.869Z",
 *     "title":        "Mr.",
 *     "first_name":   "John",
 *     "last_name":    "Doe",
 *     "status":       "active"
 *   }
 * ]
 */

length

Returns the number of items in the current results page.

Description

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

Syntax

get length(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the length of a query result

let resultLength = results.length; // 20

Perform a query and get the length of the result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultLength = results.length; // 20
  } ) ;

pageSize

Returns the query page size.

Description

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

Syntax

get pageSize(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the page size of a query result

let resultPageSize = results.pageSize; // 50

Perform a query and get the page size of the query result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultPageSize = results.pageSize; // 50
  } ) ;

partialIncludes

Indicates if referenced items have been trimmed from the results.

Description

When including a property with multiple references, each returned item can include up to 50 referenced items. If there are more than 50 referenced items, only 50 will be returned and partialIncludes will be true.

To retrieve more than 50 referenced items, use the queryReferenced() function.

Syntax

get partialIncludes(): boolean
TYPE
?
The kind of data the property stores.
boolean

Examples

Get whether there are partial includes in a query result

let partials = results.partialIncludes; // false

Perform a query and get whether there are partial includes in a query result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultPage = results.partialIncludes; // false
  } ) ;

query

Returns the query used to get the current results.

Syntax

get query(): WixDataQuery

Examples

Get the query that produced a query result

let resultQuery = results.query;

Perform a query and get the query that produced the result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultQuery = results.query;
  } ) ;

totalCount

Returns the total number of items that match the query.

Description

The totalCount returns the total number of items that match the query, not just the number of items in the current page.

Syntax

get totalCount(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the length of a query result

let resultCount = results.totalCount; // 150

Perform a query and get the length of the result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultCount = results.totalCount; // 150
  } ) ;

totalPages

Returns the total number of pages the query produced.

Description

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

Syntax

get totalPages(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the total number of pages in a query result

let resultPages = results.totalPages; // 3

Perform a query and get the total number of pages in the query result

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .find()
  .then( (results) => {
    let resultPages = results.totalPages; // 3
  } ) ;

hasNext( )

Indicates if the query has more results.

Syntax

function hasNext(): boolean
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
boolean
true if there are more results.

Examples

Get whether the query result object has more results

let hasNext = results.hasNext(); // true

hasPrev( )

Indicates the query has previous results.

Syntax

function hasPrev(): boolean
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
boolean
true if there are previous results.

Examples

Get whether the query result object has previous results

let hasPrev = results.hasPrev(); // false

next( )

Retrieves the next page of query results.

Description

The next() function retrieves the next page of query results.

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

If items are added or removed between calls to next() the values returned by WixDataQueryResult may change.

Syntax

function next(): Promise<WixDataQueryResult>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.

Fulfilled - A query result object with the next page of query results. Rejected - The errors that caused the rejection.

Examples

Get the next page of a query result

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

prev( )

Retrieves the previous page of query results.

Description

The prev() function retrieves the previous page of query results.

The page size is defined by the limit() function, can be retrieved using the pageSize property, and navigating through pages is done with the prev() and next() functions.

If items are added or removed between calls to prev() the values returned by WixDataQueryResult may change.

Syntax

function prev(): Promise<WixDataQueryResult>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.

Fulfilled - A query result object with the next page of query results. Rejected - The errors that caused the rejection.

Examples

Get the previous page of a query result

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