---
title: "Query"
description: "Query"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/typescript/reference/query"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-06-12"
---

# Query

## Query

These methods allow you to refine entry queries by applying conditions, filters, and relational data. You can filter entries based on specific field values, include referenced entries, and limit the number of results.

**Example:**

```
const query = stack.contentType("contentTypeUid").Entry().query();
```

## addParams

The addParam method adds a query parameter to the query.

```
Example:
import { BaseEntry, FindEntry } from '@contentstack/delivery-sdk'


interface BlogPostEntry extends BaseEntry {
  // custom entry types
}
const query = stack.contentType(contentType_uid).entry().query();
const result = await query
                       .addParams({"key": "value"})
                       .find<BlogPostEntry>();
```

Add key-value pairs

## addQuery

The addQuery method adds multiple query parameters to the query.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query
                       .addQuery("query_param_key", "query_param_value")
                       .find<BlogPostEntry>();
```

Add filter query key

Add the corresponding value to the filter query key

## find

The find method retrieves the details of the specified entry.

```
Example:
const result = await stack
                       .contentType("contentType1Uid")
                       .entry()
                       .query()
                       .find<BlogPostEntry>();
```

## includeCount

The includeCount method retrieves count and data of objects in the result.

```
Example:
const query = stack.contentType(contentType_uid).entry().query();
const result = await query.includeCount().find<BlogPostEntry>();
```

## orderByAscending

The orderByAscending method sorts the results in ascending order based on the specified field UID.

```
Example:
const query = stack.contentType(contentType_uid).entry().query();
const result = await query
                       .orderByAscending()
                       .find<BlogPostEntry>();
```

Field UID to sort the results

## orderByDescending

The orderByDescending method sorts the results in descending order based on the specified key.

```
Example:
const query = stack.contentType(contentType_uid).entry().query();
const result = await query
                       .orderByDescending()
                       .find<BlogPostEntry>();
```

Field UID to sort the results

## param

The param method adds query parameters to the URL.

```
Example:
const query = stack.contentType(contentType_uid).entry().query();
const result = await query
                       .param("key", "value")
                       .find<BlogPostEntry>();
```

Add any param to include in the response

Add the corresponding value of the param key

## queryOperator

The queryOperator method retrieves the entries as per the given operator.

```
Example:
import contentstack, { QueryOperation, QueryOperator } from '@contentstack/delivery-sdk';

const stack = contentstack.stack('apiKey', 'deliveryToken', 'environment');

// Create main query
const query = stack
  .contentType('contentType1Uid')
  .entry()
  .query();

// Create subquery 1
const subQuery1 = stack
  .contentType('contentType2Uid')
  .entry()
  .query()
  .where('price', QueryOperation.IS_LESS_THAN, 90);

// Create subquery 2
const subQuery2 = stack
  .contentType('contentType3Uid')
  .entry()
  .query()
  .where('discount', QueryOperation.INCLUDES, [20, 45]);

// Apply the query operator (AND/OR)
query.queryOperator(QueryOperator.AND, subQuery1, subQuery2);

// Execute the query
const result = await query.find();
console.log('Result:', result);
```

Type of query operator to apply

Query instances to apply the query to

## removeParam

The removeParam method removes a query parameter from the query.

```
Example:
const query = stack.contentType(contentType_uid).entry().query();
const result = await query
                       .removeParam("query_param_key")
                       .find<BlogPostEntry>();
```

Specify the param key you want to remove

## where

The where method filters the results based on the specified criteria.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query
                       .where(
                         "field_UID", 
                         QueryOperation.IS_LESS_THAN, 
                         ["field1", "field2"])
                       .find<BlogPostEntry>();
```

Specify the field the comparison is made from

Specify the comparison criteria

Specify the field the comparison is made to

## whereIn

The whereIn method retrieves the entries that meet the query conditions made on referenced fields.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
query.whereIn("brand");
const result = await query.find<BlogPostEntry>();
```

UID of the reference field to query

Query instance to include in the where clause

## whereNotIn

The whereNotIn method retrieves the entries that do not meet the query conditions made on referenced fields.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
query.whereNotIn("brand");
const result = await query.find<BlogPostEntry>();
```

UID of the reference field to query

Query instance to include in the where clause

## skip

The skip method will skip a specific number of entries in the output.

```
Example:
const result = await stack
                       .contentType(contentType_uid)
                       .entry()
                       .query()
                       .skip(5)
                       .find<BlogEntry>();
```

Enter the number of entries to be skipped.

## limit

The limit method will return a specific number of entries in the output.

```
Example:
const result = await stack
                       .contentType(contentType_uid)
                       .entry()
                       .query()
                       .limit(5)
                       .find<BlogEntry>();
```

Enter the maximum number of entries to be returned.

## or

The or method retrieves the entries that meet either of the conditions specified.

```
Example:
const query1 = stack.contentType('contenttype_uid').entry().query().containedIn('fieldUID', ['value']);
const query2 = stack.contentType('contenttype_uid').entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2');
const query = await stack.contentType('contenttype_uid').entry().query().or(query1, query2).find<BlogPostEntry>();
```

Array of query objects or raw queries

## and

The and method retrieves the entries that meet all the specified conditions.

```
Example:
const query1 = stack.contentType('contenttype_uid').entry().query().containedIn('fieldUID', ['value']);
const query2 = stack.contentType('contenttype_uid').entry().query().where('fieldUID', QueryOperation.EQUALS, 'value2');
const query = await stack.contentType('contenttype_uid').entry().query().and(query1, query2).find<BlogPostEntry>();
```

Array of query objects or raw queries

## containedIn

The containedIn method retrieves the entries that contain the conditions specified.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.containedIn('fieldUid', ['value1', 'value2']).find();
```

UID of the field

Array of values that are to be used to match or compare

## notContainedIn

The notContainedIn method retrieves the entries where the specified conditions are absent.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.notContainedIn('fieldUid', ['value1', 'value2']).find();
```

UID of the field

Array of values that are to be used to match or compare

## equalTo

The equalTo method retrieves entries that match the specified conditions exactly.

```
Example:
const query = await stack.contentType('contenttype_uid').entry().query().equalTo('fieldUid', 'value').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

## exists

The exists method retrieves the entries that satisfy the specified condition of existence.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.exists('fieldUid').find();
```

UID of the field

## notExists

The notExists method retrieves entries where the specified conditions are not met.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.notExists('fieldUid').find();
```

UID of the field

## getQuery

The getQuery method retrieves the entries as per the specified query.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.query({'brand': {'$nin_query': {'title': 'Apple Inc.'}}}).getQuery();


// OR

const asset = await stack.asset().query({'brand': {'$nin_query': {'title': 'Apple Inc.'}}}).getQuery();
```

UID of the field

## greaterThan

The greaterThan method retrieves the entries that are greater than the specified condition.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().greaterThan('fieldUid', 'value').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

## greaterThanOrEqualTo

The greaterThanOrEqualTo method retrieves entries that meet the specified condition of being greater than or equal to a certain value.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().greaterThanOrEqualTo('fieldUid', 'value').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

## lessThan

The lessThan method retrieves the entries that are less than the specified condition.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().lessThan('fieldUid', 'value').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

## lessThanOrEqualTo

The lessThanOrEqualTo method retrieves entries that meet the specified condition of being less than or equal to a certain value.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().lessThanOrEqualTo('fieldUid', 'value').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

## referenceIn

The referenceIn method retrieves the entries that are referenced.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().referenceIn('reference_uid', query).find<BlogPostEntry>();
```

UID of the reference field

RAW (JSON) queries

## referenceNotIn

The referenceNotIn method retrieves the entries where the referenced items are not included.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().referenceNotIn('reference_uid', query).find<BlogPostEntry>();
```

UID of the reference field

RAW (JSON) queries

## regex

The regex method retrieves entries that match a specified regular expression pattern.

```
Example:
const query = stack.contentType("contentTypeUid").entry().query();
const result = await query.regex('title','^Demo').find();
// OR
const result = await query.regex('title','^Demo', 'i').find<BlogPostEntry>();
```

UID of the field

Array of values that are to be used to match or compare

Match or compare value in entry

## search

The search method retrieves the entries that match the specified search criteria.

```
Example:
const entryQuery = await stack.contentType('contenttype_uid').query().search('key').find<BlogPostEntry>();
```

UID of the field

## tags

The tags method fetches the entries that are associated with specific tags.

```
Example:
const query = stack.contentType('contenttype_uid').query().where('title', QueryOperation.EQUALS, 'value');
const entryQuery = await stack.contentType('contenttype_uid').query().tags(['tag1']).find<BlogPostEntry>();
```

Array of tags

## Query | TypeScript Delivery SDK | Contentstack

The Query class in the TypeScript Delivery SDK refines entry queries with conditions, filters, and referenced entries to retrieve content from Contentstack.