> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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: queryReferenced(collectionId: string, item: any, propertyName: string, options: WixDataQueryReferencedOptions)

# Method package: wixData

# Method menu location: wixData --> queryReferenced

# Method Link: https://dev.wix.com/docs/velo/apis/wix-data/query-referenced.md

# Method Description:

Gets the full items referenced in the specified property.

The `queryReferenced()` function returns a Promise that resolves to the full
 items that are referenced in the specified property of the
 item from the specified collection. The Promise is rejected if the current
 user does not have read permissions for the specified collection or the
 collection containing the referenced items.

 For example, suppose you have a **Movies** collection with an **Actors**
 field that contains references
 to items in a **People** collection. Querying the **Movies** collection
 using `queryReferenced()` returns the relevant **People** items
 referenced in the **Actors** field of the specified **Movies** item. Meaning,
 it returns the full actor information for all actors in the specified movie.

 The `queryReferenced()` function can be used instead of a standard [`query()`](#query)
 with an [`include()`](https://dev.wix.com/docs/velo/api-reference/wix-data/wix-data-query/include.md) to overcome the
 limitations of the [`include()`](https://dev.wix.com/docs/velo/api-reference/wix-data/wix-data-query/include.md) function.

 You can optionally control the order of the returned referenced items by
 passing a `WixDataQueryReferencedOptions` object.

  > **Notes:**
  > - Calling the `queryReferenced()` function does not trigger any hooks.
  > - You can only use the `queryReferenced()` function with [multiple-item reference fields](https://support.wix.com/en/article/about-referencing-multiple-items-in-one-field), and not with single-item (regular) reference fields.
  > - The `queryReferenced()` function is not supported for Single Item Collections.
 > - To speed up data retrieval, the results of certain data requests are cached. Learn more about [caching data query results](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/data-api/about-caching-data-query-results.md).

 For a discussion of when to use the similar [`include()`](https://dev.wix.com/docs/velo/api-reference/wix-data/wix-data-query/include.md)
 function and when to use `queryReferenced()`, see [Querying Items that Reference Other Items](https://support.wix.com/en/article/including-referenced-data-when-filtering).



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Get referenced items

```javascript
import wixData from 'wix-data';

// ...

wixData.queryReferenced("movies", "00001", "actors")
  .then((results) => {
    if(results.items.length > 0) {
      console.log(results.items[0]); //see item below
    } else {
      // handle case where no matching items found
    }
  })
  .catch((err) => {
    console.log(err);
  });

/*  firstItem is:
 *
 *  {
 *    "_id":          "12345",
 *    "_owner":       "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 *    "_createdDate": "2017-05-24T12:33:18.938Z",
 *    "_updatedDate": "2017-05-24T12:33:18.938Z",
 *    "first_name":   "John",
 *    "last_name":    "Doe"
 *  }
 */

```

## Get referenced items using options

```javascript
import wixData from 'wix-data';

// ...

let options = {
  "order": "asc"
};

wixData.queryReferenced("movies", "00001", "actors", options)
  .then((results) => {
    if(results.items.length > 0) {
      console.log(results.items[0]); //see item below
    } else {
      // handle case where no matching items found
    }
  })
  .catch((err) => {
    console.log(err);
  });

/*  firstItem is:
 *
 *  {
 *    "_id":          "12345",
 *    "_owner":       "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
 *    "_createdDate": "2017-05-24T12:33:18.938Z",
 *    "_updatedDate": "2017-05-24T12:33:18.938Z",
 *    "first_name":   "John",
 *    "last_name":    "Doe"
 *  }
 */
```

---