The Data API is a game-changing feature in Atlas. It allows you to read and write data over HTTPS. You do not need a traditional database driver.
It is built for modern, serverless environments. Serverless functions suffer from connection limits. The HTTP Data API bypasses strict connection pooling limits.
Standard drivers maintain open TCP sockets. The Data API uses standard stateless web requests. It uses simple POST endpoints provided by Atlas.
You authenticate using a secure API Key. You pass this key in the request headers. It is completely safe when used over HTTPS.
The payload you send is pure JSON. You include the database, collection, and filter rules. Atlas processes it and responds with JSON data.
// Fetch data using standard fetch()
fetch("https://data.mongodb-api.com/app/.../endpoint/data/v1/action/findOne", {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": "YOUR_ATLAS_API_KEY"
},
body: JSON.stringify({
"dataSource": "Cluster0",
"database": "sample_mflix",
"collection": "movies",
"filter": { "year": 2015 }
})
});
The Data API supports standard CRUD methods. You can call findOne, find, insertOne, and updateOne. You can even execute complex aggregation pipelines.
Edge networks like Cloudflare Workers love the Data API. They lack full TCP support for standard drivers. The Data API runs perfectly on the Edge.
The Atlas Data API opens up new integration methods. It uses standard HTTPS requests and JSON payloads. It is ideal for serverless apps and edge deployments.
How does the Atlas Data API connect to the database?