find( )


Developer Preview

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

Returns the items that match the query.

The find() method returns a Promise that resolves to the results found by the query and some information about the results. The Promise is rejected if find() is called with incorrect permissions or if any of the methods used to refine the query is invalid.

Calling the find() method triggers the beforeQuery() and afterQuery() hooks if they have been defined.

Note: Calling find() triggers hooks for the specified collection only. It doesn't trigger hooks for referenced collections.

Use the options parameter to override default preferences:

  • Ensure the most up-to-date data is retrieved with consistentRead.
  • Prevent hooks from running with suppressHooks.
  • Get a count of all the items that match the query by setting returnTotalCount to true.

If you build a query and don't refine it with any wixDataQuery methods, find() returns the entire collection.

Method Declaration
Copy
function find(options: WixDataQueryOptions): Promise<WixDataResult>;
Method Parameters
optionsWixDataQueryOptions

Configuration options for building the query.

Returns
Return Type:Promise<WixDataResult>

This example demonstrates how to run a find() on a query() that was previously built and stored in a variable.

JavaScript
async function findItemsMatchingQuery(query) { const results = await query.find(); if (results.items.length > 0) { const items = results.items; const firstItem = items[0]; const pageSize = results.pageSize; const currentPage = results.currentPage; const hasNext = results.hasNext(); const hasPrev = results.hasPrev(); const length = results.length; } else { // handle case where no matching items found } }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?