When you execute a query with the find()
function, it returns a Promise that resolves to a BookingsQueryResult
object.
This object contains the items that match the query, information about the
query itself, and functions for paging through the query results.
Returns the index of the current results page number.
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.
let resultPage = results.currentPage; // 0
Returns the items that match the query.
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.
When no items match the query, the items
array is empty.
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"
* }
* ]
*/
let resultLength = results.length; // 20
let resultPageSize = results.pageSize; // 50
Returns the query used to get the current results.
let resultQuery = results.query;
/* resultQuery:
*
* "filterTree": {
* "$and": [
* {
* "status": {
* "$hasSome": [
* "PENDING_APPROVAL",
* "CONFIRMED",
* "DECLINED",
* "CANCELED",
* "PENDING_CHECKOUT",
* "PENDING"
* ]
* }
* }
* ]
* },
* "invalidArguments": [],
* "sort": [
* {
* "fieldName": "created",
* "order": "DESC"
* }
* ],
* "paging": {
* "offset": 9
* },
* "pagingMethod": "OFFSET"
*
*/
Returns the total number of items that match the query.
The totalCount
returns the total number of items that match the query,
not just the number of items in the current page.
let resultCount = results.totalCount; // 150
let resultPages = results.totalPages; // 3
Indicates if the query has more results.
function hasNext(): boolean;
let hasNext = results.hasNext(); // true
Indicates the query has previous results.
function hasPrev(): boolean;
let hasPrev = results.hasPrev(); // false