Lesson 28 +10 XP

The Data API

The MongoDB Data API lets you query and update Atlas data over plain HTTPS endpoints - no language driver required. It's handy when a driver isn't available or is overkill.

When to use it

  • Drivers aren't available for your platform.
  • You want a simple HTTP request instead of a driver.
  • Serverless functions and quick integrations.

Enabling the Data API

  • In the Atlas UI: 1. Open Data API and enable it for your cluster.
  1. Choose an access level (No Access, Read Only, Read and Write, or Custom).
  1. Create a Data API key - it's shown only once, so save it.
  1. Note the App ID from the endpoint URL.

Example: findOne via HTTPS


bash
curl - location - request POST 'https://data.mongodb-api.com/app/<DATA API APP ID>/endpoint/data/v1/action/findOne' \ - header 'Content-Type: application/json' \ - header 'api-key: <DATA API KEY>' \ - data-raw '{
  "dataSource": "<CLUSTER NAME>",
  "database": "sample_mflix",
  "collection": "movies",
  "projection": { "title": 1 }
}'

The endpoints

The Data API exposes these actions:

ActionPurpose
findOne / findRead documents
insertOne / insertManyCreate documents
updateOne / updateManyUpdate documents
deleteOne / deleteManyDelete documents
aggregateRun an aggregation pipeline

Every request body includes dataSource (your cluster name), database, and collection.

TL;DR

  • The Data API exposes CRUD + aggregation over HTTPS.
  • Requires enabling it and a Data API key.
  • A good fallback when drivers aren't available.