> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: beforeQuery(query: WixDataQuery, context: HookContext) # Method package: wixDataHooks # Method menu location: wixDataHooks --> beforeQuery # Method Link: https://dev.wix.com/docs/velo/events-service-plugins/data/hooks/wix-data-hooks/before-query.md # Method Description: A hook that is triggered before a `find()` operation. The `beforeQuery()` hook runs when: + The [`find`](wix-data.WixDataQuery.html#find) function is called. + An action is performed on a dataset that retrieves items from the collection. + The collection is viewed in the CMS. + An item is exported from the collection. The hook also runs when an action is performed on a dataset that retrieves items from the collection that the dataset is connected to. Return a query or a Promise that resolves to a query from the `beforeQuery()` function. The returned query will be used as the query for the [`find`](wix-data.WixDataQuery.html#find) operation. Often, you will modify the query that is received in the `query` parameter by calling one or more [`WixDataQuery`](wix-data.WixDataQuery.html) functions. If the returned value is of the wrong type, the value is ignored. A rejected Promise blocks the call to [`find()`](wix-data.WixDataQuery.html#find) and also calls the [`onFailure()`](#onFailure) hook if it has been registered. Because the `beforeQuery()` hook is called before [`find()`](wix-data.WixDataQuery.html#find) is executed, it can affect the query that is used to retrieve items or block the [`find()`](wix-data.WixDataQuery.html#find). # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## A beforeQuery hook ```javascript // In data.js export function myCollection_beforeQuery(query, context) { let hookContext = context; // see below // some change to the received query return query; } /* * hookContext: * * { * "collectionName": "myCollection", * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3", * "userRole": "siteOwner" * } */ ``` ## Change the query to be executed using the beforeQuery hook ```javascript // In data.js export function myCollection_beforeQuery(query, context) { let hookContext = context; // see below // some change to the received query let newQuery = query.eq("status", "active"); return newQuery; } /* * hookContext: * * { * "collectionName": "myCollection", * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3", * "userRole": "siteOwner" * } */ ``` ---