---
title: "DataSync MongoDB SDK API Reference"
description: "Comprehensive API reference for Contentstack DataSync MongoDB SDK to query, filter, and manage CMS content directly from your MongoDB database."
url: "https://www.contentstack.com/docs/developers/sdks/datasync-sdk/typescript/mongodb/reference"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2025-09-18"
---

# DataSync MongoDB SDK API Reference

## DataSync MongoDB SDK API Reference

The Contentstack DataSync MongoDB SDK enables developers to synchronize and query Contentstack data directly from a MongoDB database. This approach reduces API calls by serving content directly from local storage, optimizing delivery performance.

**Additional Resource:** To know more about DataSync MongoDB SDK, refer to the [Get Started with DataSync MongoDB SDK](/docs/developers/sdks/datasync-sdk/typescript/get-started-with-datasync-mongodb-sdk/) documentation.

## Stack

The [Stack](/docs/developers/set-up-stack/about-stack) instance serves as the primary interface for interacting with your Contentstack data stored in MongoDB. It provides methods to query [entries](/docs/content-managers/author-content/about-entries), [assets](/docs/content-managers/working-with-assets/about-assets), and [content type](/docs/developers/create-content-types/about-content-types) schemas.

**Example:**

const Stack = Contentstack.Stack(config);

Name of the MongoDB database. Defaults to 'contentstack-db'.

MongoDB connection URI. Defaults to 'mongodb://localhost:27017'.

MongoDB connection options. Refer to [MongoClient](https://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html) Options for details.

## Global

The Global class provides a rich set of methods that allows developers to build advanced queries on top of MongoDB-synced Contentstack data. These methods enable filtering, projection, sorting, reference handling, and more.

## and

The and method combines multiple query conditions using a logical AND operator and returns entries that meet all the specified conditions.

Filters defining the conditions to match the entries.

## ascending

The ascending method sorts the fetched entries in ascending order based on the specified field.

The field to sort in ascending order

## asset

The asset method retrieves a single asset by its UID.

UID of the asset to fetch; if not provided, returns the first asset found.

## assets

The assets method retrieves a list of all assets.

## close

The close method closes the MongoDB connection.

## connect

The connect method establishes a connection to MongoDB with optional configuration overrides

Provides optional overrides or MongoDB-specific settings to customize query behavior.

## containedIn

The containedIn method retrieves entries where the specified field's value matches any value in the provided array.

The field to compare values against in the query.

The value or values to compare against the field.

## contentType

The contentType method specifies the content type to query.

UID of the content type to run the query against.

## contentTypes

The contentTypes method retrieves schemas of all content types.

## count

The count method returns the total number of entries or assets that match the specified query.

A filter object that defines conditions for the query.

## descending

The descending method sorts the fetched entries in descending order based on the specified field.

The field to sort in descending order

## entries

The entries method initiates a query for a set of entries within the specified content type.

UID of the entry to fetch; if not provided, returns the first entry found.

## entry

The entry method retrieves a single entry by its UID from the specified content type.

UID of the entry to fetch; if not provided, returns the first entry found.

## except

The except method excludes the specified fields from the response.

Array of field UIDs, using dot notation for querying embedded documents

## excludeReferences

The excludeReferences method excludes all references of the entries being returned.

**Note:** On calling this, referenced entries and assets will not be included in the result.

## exists

The exists method filters entries that contain the specified field.

Field to check existence for

## fetch

The fetch method executes a query using the provided query object. It returns a single entry/asset/content type object after applying all filters and references.

Query object that overrides all previous query filters

## find

The find method processes and executes all built queries, and returns the matching result.

Query object that overrides all previous query filters

## findOne

**Note:** This method is deprecated. Use fetch instead.

The findOne method executes a query using the provided query object. It returns a single entry/asset/content type object after applying all filters and references.

Query object that overrides all previous query filters

## getQuery

The getQuery method exposes the query object built using chained query methods.

## greaterThan

The greaterThan method retrieves entries where the specified field’s value is greater than the provided value.

The field to compare values against in the query.

The value or values to compare against the field.

## greaterThanOrEqualTo

The greaterThanOrEqualTo method retrieves entries where the specified field’s value is greater than or equal to the provided value.

The field to compare values against in the query.

The value or values to compare against the field.

## include

The include method includes specific reference fields in the response.

An array of reference field UIDs to include

## includeContentType

The includeContentType method includes the content type schema of the entries in the response.

## includeCount

The includeCount method includes the total count of matching entries in the result response.

## includeReferences

The includeReferences method includes all the references of your queried entries (default depth 2).

**Note:** To increase the depth of the references fetched, call [.referenceDepth(number)](/docs/developers/sdks/datasync-sdk/typescript/mongodb/reference#referencedepth).

## language

The language method sets the locale to be used when querying entries.

Language code to use

## lessThan

The lessThan method retrieves entries where the value of a specified field is less than the provided value.

The field to compare values against in the query.

The value or values to compare against the field.

## lessThanOrEqualTo

The lessThanOrEqualTo method retrieves entries where the specified field’s value is less than or equal to the given value.

The field to compare values against in the query.

The value or values to compare against the field.

## limit

The limit method restricts the number of entries returned by the query.

Maximum number of results to return

## notContainedIn

The notContainedIn method retrieves entries where the specified field’s value does not match any value in the given array.

The field to compare values against in the query.

Array of values to exclude

## notEqualTo

The notEqualTo method retrieves entries where the specified field’s value does not equal the given value.

The field to compare values against in the query.

The value or values to compare against the field.

## notExists

The notExists method filters entries that do not contain the specified field.

The field to check for absence in the entry.

## only

The only method includes only the specified fields in the result set.

Array of field UIDs to be included (dot notation supported)

## or

The or method combines multiple conditions using the logical OR operator and returns entries that match at least one of the conditions.

Array of query condition objects

## query

The query method initializes a query builder with the specified raw MongoDB query.

Raw MongoDB query object

## queryReferences

The queryReferences method allows you to perform a query on reference fields that are included using .includeReferences().

Query filter for referenced entries

## referenceDepth

The referenceDepth method overrides the default reference resolution depth of 2 when using .includeReferences().

Desired nested reference depth

## regex

The regex method retrieves entries where the value of the specified field matches the given regular expression.

The unique identifier of the field to match in the query

The regex pattern to test against the field's value.

Regex options to apply (e.g., 'i' for case-insensitive).

## schema

The schema method fetches the schema definition for the specified content type.

UID of the content type

## schemas

The schemas method fetches all content type schemas.

## skip

The skip method skips the specified number of entries from the start of the result set.

Number of entries to skip

## tags

The tags method filters entries/assets that include the specified tags.

An array of tags to match

## where

The where method applies a custom JavaScript expression to evaluate and filter entries.

JavaScript expression as a string