query( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Creates a query to retrieve items from a database collection.

The query() method builds a query to retrieve data items from a collection and returns a WixDataQuery object, which contains the query definition. You can refine the query by chaining WixDataQuery methods onto the query. WixDataQuery methods enable you to sort, filter, and control the query results.

The methods chained to query() are applied in the order they are called. For example, if you sort by an age field in ascending order and then by a name field in descending order, the results are sorted first by the age of the items. If there are multiple results with the same age, they are further sorted by name in descending order, per age value.

Finally, to run the query, chain find() or distinct() as the last method.

The query() method runs with the following WixDataQuery defaults that you can override:

  • skip: 0
  • limit: 50
  • descending: by _createdDate
  • include: none

Notes:

  • When calling query() immediately following an update to your collection, the data retrieved might not contain the most recent changes. If you need the most up-to-date data, set the options.consistentRead parameter of the find() or distinct() methods to true. Learn more about Wix Data and Eventual Consistency.
  • Items marked in the CMS as hidden are not retrieved.
  • If the collection that you are querying has references to other collections, by default the data from referenced collections is not retrieved. To retrieve data from the referenced items, specify them using the include() method.
  • When querying Wix app collections, make sure the fields you use to refine your query support the intended operations. Learn more about querying by Wix app collection fields.
Permissions
Read Data Items
Learn more about app permissions.
Method Declaration
Copy
Method Parameters
dataCollectionIdstringRequired

ID of the collection to run the query on.

Returns
Return Type:WixDataQuery
Did this help?