MongoDB Atlas Data API (v1)

Download OpenAPI specification:Download

A fully-managed API to read, write, and aggregate data in MongoDB Atlas. The Data API is powered by serverless Atlas Functions and secured with user authentication and role-based permissions. To learn more about the Data API, see Atlas Data API.

Set Up the Data API

Before you can use the Data API, you must enable and configure it in an Atlas App Services App. The configuration controls how the App's users authenticate, authorize requests, and interact with the API.

To learn how to start using the Data API in your App, see Set up the Data API.

Authenticate Requests

Your Data API configuration in App Services controls how users authenticate their API requests. In most cases, you will use Application authentication, which lets users log in with one of the App's authentication providers. Users can either provide their login credentials directly in every request or provide a reusable access token for an authenticated session.

To learn more, see Authenticate Data API Requests.

Find One Document

Find a single document that matches a query.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
required
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

object

A MongoDB projection for matched documents returned by the operation.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    },
  • "projection": {
    }
}

Response samples

Content type
{
  • "document": {
    }
}

Find Documents

Find multiple documents that match a query.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
required
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

object

A MongoDB projection for matched documents returned by the operation.

sort
object

A MongoDB sort expression that indicates sorted field names and directions.

limit
number

The maximum number of matching documents to include the in the response.

skip
number

The number of matching documents to omit from the response.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    },
  • "projection": {
    },
  • "sort": {
    },
  • "limit": 10
}

Response samples

Content type
{
  • "documents": [
    ]
}

Insert One Document

Insert a single document into a collection.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

document
required
object

A document to insert into the collection.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "document": {
    }
}

Response samples

Content type
{
  • "insertedId": "6193504e1be4ab27791c8133"
}

Insert Documents

Insert multiple documents into a collection.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

documents
required
Array of objects

A list of documents to insert into the collection.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "documents": [
    ]
}

Response samples

Content type
{
  • "insertedIds": [
    ]
}

Update One Document

Update a single document in a collection.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
required
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

update
required
object

A MongoDB update expression to apply to matching documents. For a list of all update operators that the Data API supports, see Update Operators.

upsert
boolean
Default: false

When true, if the update filter does not match any existing documents, then insert a new document based on the filter and the specified update operation.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    },
  • "update": {
    },
  • "upsert": false
}

Response samples

Content type
{
  • "matchedCount": 1,
  • "modifiedCount": 1
}

Update Documents

Update multiple documents in a collection.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
required
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

update
required
object

A MongoDB update expression to apply to matching documents. For a list of all update operators that the Data API supports, see Update Operators.

upsert
boolean
Default: false

When true, if the update filter does not match any existing documents, then insert a new document based on the filter and the specified update operation.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    },
  • "update": {
    }
}

Response samples

Content type
{
  • "matchedCount": 12,
  • "modifiedCount": 12
}

Delete One Document

Delete a single document that matches a query.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    }
}

Response samples

Content type
{
  • "deletedCount": 1
}

Delete Documents

Delete multiple documents that match a query.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

filter
object

A MongoDB query filter that matches documents. For a list of all query operators that the Data API supports, see Query Operators.

Responses

Request samples

Content type
{
  • "dataSource": "mongodb-atlas",
  • "database": "todo",
  • "collection": "tasks",
  • "filter": {
    }
}

Response samples

Content type
{
  • "deletedCount": 12
}

Aggregate Documents

Run an aggregation pipeline.

Authorizations:
AccessToken(EmailPassword) ApiKeyCustomJwt
Request Body schema:
dataSource
required
string

The name of a linked MongoDB Atlas data source. This is commonly "mongodb-atlas" though it may be different in your App if you chose a different name when you created the data source.

database
required
string

The name of a database in the specified data source.

collection
required
string

The name of a collection in the specified database.

pipeline
required
Array of objects

An array of aggregation stages.

Responses

Request samples

Content type
[
  • {
    },
  • {
    }
]

Response samples

Content type
[
  • {
    },
  • {
    }
]