wix-data.WixDataQueryResult

wix-data.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.

Contents

currentPage Returns the index of the current results page number.
items Returns the items that match the query.
length Returns the number of items in the current results page.
pageSize Returns the query page size.
partialIncludes Indicates if referenced items have been trimmed from the results.
query Returns the query used to get the current results.
totalCount Returns the total number of items that match the query.
totalPages Returns the total number of pages the query produced.
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

currentPage

Returns the index of the current results page number.

Syntax

get currentPage(): 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.

Type

Number

Examples

Get the current page index of a query result

bGV0IHJlc3VsdFBhZ2UgPSByZXN1bHRzLmN1cnJlbnRQYWdlOyAvLyAwCg==
let resultPage = results.currentPage; // 0

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

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRQYWdlID0gcmVzdWx0cy5jdXJyZW50UGFnZTsgLy8gMAogIH0gKSA7Cg==
import wixData from 'wix-data';

// ...

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

items

Returns the items that match the query.

Syntax

get items(): Object[]

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.

Type

Object[ ]

Examples

Get the items of a query result

bGV0IGl0ZW1zID0gcmVzdWx0cy5pdGVtczsKCi8qCiAqIFsKICogICB7CiAqICAgICAiX2lkIjogICAgICAgICAgIjEyMzQiLAogKiAgICAgIl9vd25lciI6ICAgICAgICJmNDVqZjhkMi1ncmtqLTJvcGQtNG92ay05cmZqNHdvNXR2ajMiLAogKiAgICAgIl9jcmVhdGVkRGF0ZSI6ICIyMDE3LTA1LTI5VDA4OjM1OjUyLjM0NFoiLAogKiAgICAgIl91cGRhdGVkRGF0ZSI6ICIyMDE3LTA1LTI5VDA4OjM1OjUyLjM0NFoiLAogKiAgICAgInRpdGxlIjogICAgICAgICJEci4iLAogKiAgICAgImZpcnN0X25hbWUiOiAgICJKYW5lIiwKICogICAgICJsYXN0X25hbWUiOiAgICAiRG9lIiwKICogICAgICJzdGF0dXMiOiAgICAgICAiYWN0aXZlIgogKiAgIH0sCiAqICAgewogKiAgICAgIl9pZCI6ICAgICAgICAgICI1Njc4IiwKICogICAgICJfb3duZXIiOiAgICAgICAiZjQ1amY4ZDItZ3Jrai0yb3BkLTRvdmstOXJmajR3bzV0dmozIiwKICogICAgICJfY3JlYXRlZERhdGUiOiAiMjAxNy0wNS0yNVQxMjo0ODo1Ni41NzJaIiwKICogICAgICJfdXBkYXRlZERhdGUiOiAiMjAxNy0wNS0yOVQwNzozMDoxNS44NjlaIiwKICogICAgICJ0aXRsZSI6ICAgICAgICAiTXIuIiwKICogICAgICJmaXJzdF9uYW1lIjogICAiSm9obiIsCiAqICAgICAibGFzdF9uYW1lIjogICAgIkRvZSIsCiAqICAgICAic3RhdHVzIjogICAgICAgImFjdGl2ZSIKICogICB9CiAqIF0KICovCg==
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

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBpdGVtcyA9IHJlc3VsdHMuaXRlbXM7IC8vIHNlZSBiZWxvdwogIH0gKSA7CgovKiBpdGVtczoKICoKICogWwogKiAgIHsKICogICAgICJfaWQiOiAgICAgICAgICAiMTIzNCIsCiAqICAgICAiX293bmVyIjogICAgICAgImY0NWpmOGQyLWdya2otMm9wZC00b3ZrLTlyZmo0d281dHZqMyIsCiAqICAgICAiX2NyZWF0ZWREYXRlIjogIjIwMTctMDUtMjlUMDg6MzU6NTIuMzQ0WiIsCiAqICAgICAiX3VwZGF0ZWREYXRlIjogIjIwMTctMDUtMjlUMDg6MzU6NTIuMzQ0WiIsCiAqICAgICAidGl0bGUiOiAgICAgICAgIkRyLiIsCiAqICAgICAiZmlyc3RfbmFtZSI6ICAgIkphbmUiLAogKiAgICAgImxhc3RfbmFtZSI6ICAgICJEb2UiLAogKiAgICAgInN0YXR1cyI6ICAgICAgICJhY3RpdmUiCiAqICAgfSwKICogICB7CiAqICAgICAiX2lkIjogICAgICAgICAgIjU2NzgiLAogKiAgICAgIl9vd25lciI6ICAgICAgICJmNDVqZjhkMi1ncmtqLTJvcGQtNG92ay05cmZqNHdvNXR2ajMiLAogKiAgICAgIl9jcmVhdGVkRGF0ZSI6ICIyMDE3LTA1LTI1VDEyOjQ4OjU2LjU3MloiLAogKiAgICAgIl91cGRhdGVkRGF0ZSI6ICIyMDE3LTA1LTI5VDA3OjMwOjE1Ljg2OVoiLAogKiAgICAgInRpdGxlIjogICAgICAgICJNci4iLAogKiAgICAgImZpcnN0X25hbWUiOiAgICJKb2huIiwKICogICAgICJsYXN0X25hbWUiOiAgICAiRG9lIiwKICogICAgICJzdGF0dXMiOiAgICAgICAiYWN0aXZlIgogKiAgIH0KICogXQogKi8K
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

length

Returns the number of items in the current results page.

Syntax

get length(): Number

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.

Type

Number

Examples

Get the length of a query result

bGV0IHJlc3VsdExlbmd0aCA9IHJlc3VsdHMubGVuZ3RoOyAvLyAyMAo=
let resultLength = results.length; // 20

Perform a query and get the length of the result

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRMZW5ndGggPSByZXN1bHRzLmxlbmd0aDsgLy8gMjAKICB9ICkgOwo=
import wixData from 'wix-data';

// ...

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

pageSize

Returns the query page size.

Syntax

get pageSize(): Number

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.

Type

Number

Examples

Get the page size of a query result

bGV0IHJlc3VsdFBhZ2VTaXplID0gcmVzdWx0cy5wYWdlU2l6ZTsgLy8gNTAK
let resultPageSize = results.pageSize; // 50

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

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRQYWdlU2l6ZSA9IHJlc3VsdHMucGFnZVNpemU7IC8vIDUwCiAgfSApIDsK
import wixData from 'wix-data';

// ...

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

partialIncludes

Indicates if referenced items have been trimmed from the results.

Syntax

get partialIncludes(): Boolean

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.

Type

Boolean

Examples

Get whether there are partial includes in a query result

bGV0IHBhcnRpYWxzID0gcmVzdWx0cy5wYXJ0aWFsSW5jbHVkZXM7IC8vIGZhbHNlCg==
let partials = results.partialIncludes; // false

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

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRQYWdlID0gcmVzdWx0cy5wYXJ0aWFsSW5jbHVkZXM7IC8vIGZhbHNlCiAgfSApIDsK
import wixData from 'wix-data';

// ...

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

query

Returns the query used to get the current results.

Syntax

get query(): WixDataQuery

Type

WixDataQuery

Examples

Get the query that produced a query result

bGV0IHJlc3VsdFF1ZXJ5ID0gcmVzdWx0cy5xdWVyeTsK
let resultQuery = results.query;

Perform a query and get the query that produced the result

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRRdWVyeSA9IHJlc3VsdHMucXVlcnk7CiAgfSApIDsK
import wixData from 'wix-data';

// ...

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

totalCount

Returns the total number of items that match the query.

Syntax

get totalCount(): Number

Description

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

Type

Number

Examples

Get the length of a query result

bGV0IHJlc3VsdENvdW50ID0gcmVzdWx0cy50b3RhbENvdW50OyAvLyAxNTAK
let resultCount = results.totalCount; // 150

Perform a query and get the length of the result

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRDb3VudCA9IHJlc3VsdHMudG90YWxDb3VudDsgLy8gMTUwCiAgfSApIDsK
import wixData from 'wix-data';

// ...

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

totalPages

Returns the total number of pages the query produced.

Syntax

get totalPages(): Number

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.

Type

Number

Examples

Get the total number of pages in a query result

bGV0IHJlc3VsdFBhZ2VzID0gcmVzdWx0cy50b3RhbFBhZ2VzOyAvLyAzCg==
let resultPages = results.totalPages; // 3

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

aW1wb3J0IHdpeERhdGEgZnJvbSAnd2l4LWRhdGEnOwoKLy8gLi4uCgp3aXhEYXRhLnF1ZXJ5KCJteUNvbGxlY3Rpb24iKQogIC5maW5kKCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCByZXN1bHRQYWdlcyA9IHJlc3VsdHMudG90YWxQYWdlczsgLy8gMwogIH0gKSA7Cg==
import wixData from 'wix-data';

// ...

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

hasNext( )

Indicates if the query has more results.

function hasNext(): boolean

Return Value

Boolean true if there are more results.

Examples

Get whether the query result object has more results

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

hasPrev( )

Indicates the query has previous results.

function hasPrev(): boolean

Return Value

Boolean true if there are previous results.

Examples

Get whether the query result object has previous results

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

next( )

Retrieves the next page of query results.

function next(): Promise<WixDataQueryResult>

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.

Return Value

Returns a Promise

On fulfillment WixDataQueryResult A query result object with the next page of query results.
On rejection Error The errors that caused the rejection.

Examples

Get the next page of a query result

b2xkUmVzdWx0cy5uZXh0KCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBuZXdSZXN1bHRzID0gcmVzdWx0czsKICAgIGxldCBpdGVtcyA9IG5ld1Jlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IG5ld1Jlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IG5ld1Jlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSBuZXdSZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSBuZXdSZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IG5ld1Jlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSBuZXdSZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSBuZXdSZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IG5ld1Jlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
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( )

prev( )

Retrieves the previous page of query results.

function prev(): Promise<WixDataQueryResult>

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.

Return Value

Returns a Promise

On fulfillment WixDataQueryResult A query result object with the next page of query results.
On rejection Error The errors that caused the rejection.

Examples

Get the previous page of a query result

b2xkUmVzdWx0cy5wcmV2KCkKICAudGhlbiggKHJlc3VsdHMpID0+IHsKICAgIGxldCBuZXdSZXN1bHRzID0gcmVzdWx0czsKICAgIGxldCBpdGVtcyA9IG5ld1Jlc3VsdHMuaXRlbXM7CiAgICBsZXQgZmlyc3RJdGVtID0gaXRlbXNbMF07CiAgICBsZXQgdG90YWxDb3VudCA9IG5ld1Jlc3VsdHMudG90YWxDb3VudDsKICAgIGxldCBwYWdlU2l6ZSA9IG5ld1Jlc3VsdHMucGFnZVNpemU7CiAgICBsZXQgY3VycmVudFBhZ2UgPSBuZXdSZXN1bHRzLmN1cnJlbnRQYWdlOwogICAgbGV0IHRvdGFsUGFnZXMgPSBuZXdSZXN1bHRzLnRvdGFsUGFnZXM7CiAgICBsZXQgaGFzTmV4dCA9IG5ld1Jlc3VsdHMuaGFzTmV4dCgpOwogICAgbGV0IGhhc1ByZXYgPSBuZXdSZXN1bHRzLmhhc1ByZXYoKTsKICAgIGxldCBsZW5ndGggPSBuZXdSZXN1bHRzLmxlbmd0aDsKICAgIGxldCBxdWVyeSA9IG5ld1Jlc3VsdHMucXVlcnk7CiAgfSApCiAgLmNhdGNoKCAoZXJyb3IpID0+IHsKICAgIGxldCBlcnJvck1zZyA9IGVycm9yLm1lc3NhZ2U7CiAgICBsZXQgY29kZSA9IGVycm9yLmNvZGU7CiAgfSApOwo=
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;
  } );