Creates a query for retrieving items from a database collection.
The query()
function builds a query on the specified collection and returns
a WixDataQuery
object.
The returned object contains the query definition which is typically used
to run the query using the find()
function.
You can refine the query by chaining WixDataQuery
functions onto the query. WixDataQuery
functions enable you to sort,
filter, and control the results a query returns.
The query()
runs with the following WixDataQuery
defaults that you can override:
skip
: 0
limit
: 50
descending
: by _createdDate
include
: noneThe functions that are chained to query()
are applied in the order they
are called. For example, if you sort on an age
property in ascending
order and then on a name
property in descending order, the results are
sorted first by the age of the items and then, if there are multiple
results with the same age, the items are sorted by name in descending
order, per age value.
If the collection that you are querying has references to other collections, by default, the data from referenced collections will not be retrieved. To get the data from the referenced items, you must either use the include()
chained function before find()
or use the queryReferenced()
function instead of query()
.
Items marked as hidden in the collection are not returned.
When working with Wix app collections, fields in the collections have the following permissions:
Note:
When using the query()
or get()
functions or another data retrieval method following a change to your database collection,
the data retrieved may not contain your most recent changes. See Wix-data and Eventual Consistency for more information. To solve this problem,
you can use the setTimeout()
function to delay retrieving data following any changes to your database collection.
The ID of the collection to run the query on.
To find your collectionId, select the Databases tab in the Velo Sidebar. Hover over your collection, click the three dots, and select Edit Settings.