MongoDB Data API: A Driverless Approach to Data Management

Discover the MongoDB Data API, a flexible way to interact with your MongoDB Atlas databases using HTTP endpoints. Learn how to perform read and write operations, including creating, reading, updating, deleting, and aggregating documents, without the need for language-specific drivers. Streamline your MongoDB development with the MongoDB Data API.



MongoDB Data API

The MongoDB Data API allows you to query and update data in a MongoDB Atlas database via HTTPS endpoints, without needing language-specific drivers. This is useful when drivers are not available or when they're too complex for your needs.

Read & Write Operations

The Data API supports various operations, including creating, reading, updating, deleting, and aggregating documents in a MongoDB Atlas database.

Cluster Configuration

To use the Data API, enable it from the Atlas UI:

  1. Navigate to Data API in the MongoDB Atlas dashboard's left menu.
  2. Select the data source(s) you want to enable and click Enable the Data API.

Access Level

By default, no access is granted. Choose the access level for the Data API:

  • No Access
  • Read Only
  • Read and Write
  • Custom Access

Data API Key

Create a Data API key for authentication:

  1. Click Create API Key, enter a name, and click Generate API Key.
  2. Save the API key securely as you won’t be able to see it again.

Sending a Data API Request

Use curl to send a request to the database. Here's an example of finding the first document in the movies collection of the sample_mflix database:

Example: Find One Document

curl --location --request POST 'https://data.mongodb-api.com/app//endpoint/data/v1/action/findOne' \
--header 'Content-Type: application/json' \
--header 'Access-Control-Request-Headers: *' \
--header 'api-key: ' \
--data-raw '{
    "dataSource": "",
    "database": "sample_mflix",
    "collection": "movies",
    "projection": {"title": 1}
}'
        

Data API Endpoints

The Data API provides several endpoints, all starting with the base URL: https://data.mongodb-api.com/app//endpoint/data/v1/action/

  • Find a Single Document
    POST /findOne

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": ,
      "projection": 
    }
            
  • Find Multiple Documents
    POST /find

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": ,
      "projection": ,
      "sort": ,
      "limit": ,
      "skip": 
    }
            
  • Insert a Single Document
    POST /insertOne

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "document": 
    }
            
  • Insert Multiple Documents
    POST /insertMany

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "documents": [, , ...]
    }
            
  • Update a Single Document
    POST /updateOne

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": ,
      "update": ,
      "upsert": true|false
    }
            
  • Update Multiple Documents
    POST /updateMany

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": ,
      "update": ,
      "upsert": true|false
    }
            
  • Delete a Single Document
    POST /deleteOne

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": 
    }
            
  • Delete Multiple Documents
    POST /deleteMany

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "filter": 
    }
            
  • Aggregate Documents
    POST /aggregate

    Request Body Example:

    
    {
      "dataSource": "",
      "database": "",
      "collection": "",
      "pipeline": [, ...]
    }