> 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:

data.items.query(dataCollectionId: string)

# Method Link:

https://dev.wix.com/docs/sdk/business-solutions/data/items/query.md

# Method Description:

undefined

# Method Permissions:



# Method Permissions Scopes IDs:

undefined



# Method Code Examples:

## Build a query

```javascript
import { items } from "@wix/data";

const query = items.query("myCollection");
```



## Build and perform a query

```javascript
import { items } from "@wix/data";

async function queryItems() {
  const results = await items.query("myCollection").find();
  if(results.items.length > 0) {
    console.log(results.items[0]); // See below
  } else {
    // handle case where no matching items found
  }
}

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

## Build and perform a query using data options

```javascript
import { items } from "@wix/data";

async function queryItems() {
  const results = await items.query("myCollection")
    .eq("title", "Dr.")
    .find();
    
  if(results.items.length > 0) {
    console.log(results.items[0]); //see firstItem below
  } else {
    // handle case where no matching items found
  }
}

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

## Create, filter, sort, limit, and run a query

```javascript
import { items } from "@wix/data";

async function queryItems() {
  const results = await items.query("myCollection")
    .eq("status", "active")
    .gt("age", 25)
    .ascending("last_name", "first_name")
    .limit(10)
    .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
  }
}
```

## Build a query incrementally

```javascript
import { items } from "@wix/data";

async function runQuery(low, high) {
  let myQuery = items.query("myCollection");

  if(low) {
    myQuery = myQuery.ge("price", low);
  }

  if(high) {
    myQuery = myQuery.le("price", high);
  }

  const results = await myQuery.find();
 
  if(results.items.length > 0) {
    $w("#myTable").rows = results.items;
  } else {
    $w("#myTable").collapse();
  }
}

```

## Build a query using `include()` to include the referenced collection cities, based on the field "city" from myCollection

```javascript
import { items } from "@wix/data";

async function queryItems() {
  const results = await items.query("myCollection")
    .include("city")
    .find();

  if (results.length > 0) {
    const firstItem = results.items[0]
    console.log(firstItem);
  }
}

/*  firstItem is:
 *
 *  {
 *    "_id": "1d8a1d97-93d3-4d6c-9a0f-c279058b4aa5",
 *    "_owner": "81c9168e-95b8-47fd-8e6a-ad9fdf71b38e",
 *    "_createdDate": "2020-08-03T10:26:26.825Z",
 *    "_updatedDate": "2020-08-03T10:27:01.558Z",
 *    "first_name": "Betty",
 *    "last_name": "Boop",
 *    "city": {
 *      "_id": "a99daca6-0400-4ef1-8d74-de3f9095bf0b",
 *      "_owner": "81c9168e-95b8-47fd-8e6a-ad9fdf71b38e",
 *      "_createdDate": "2020-08-03T10:22:39.114Z",
 *      "_updatedDate": "2020-08-03T10:23:25.042Z",
 *      "city_name": "Los Angeles",
 *      "state": "California"
 *    }
 */
```

## Query a collection using a custom function

```javascript
import { items } from "@wix/data";

// Code for a read operation using query() //

async function readGreetings() {
  const results = await items.query('Greetings').ascending('language').find();

  return results.items;
}

```

## default

```javascript
try {
      const { items } = await items.query("collection-0.05596339503499825").find();
      return items;
    } catch (error) {
      console.error(error);
      throw error;
   }
```