Query MongoDB Atlas — collections, documents, and aggregations via the Data API.
Query collections and documents via the MongoDB Atlas Data API.
MONGODB_URI - MongoDB connection URI or Atlas Data API keycurl -s -X POST -H "Content-Type: application/json" \
-H "api-key: $MONGODB_URI" \
"https://data.mongodb-api.com/app/data-xxx/endpoint/data/v1/action/find" \
-d '{"dataSource":"Cluster0","database":"mydb","collection":"mycoll","filter":{},"limit":10}' | jq '.documents[]'
curl -s -X POST -H "Content-Type: application/json" \
-H "api-key: $MONGODB_URI" \
"https://data.mongodb-api.com/app/data-xxx/endpoint/data/v1/action/insertOne" \
-d '{"dataSource":"Cluster0","database":"mydb","collection":"mycoll","document":{"name":"test","value":42}}' | jq '{insertedId}'
curl -s -X POST -H "Content-Type: application/json" \
-H "api-key: $MONGODB_URI" \
"https://data.mongodb-api.com/app/data-xxx/endpoint/data/v1/action/aggregate" \
-d '{"dataSource":"Cluster0","database":"mydb","collection":"mycoll","pipeline":[{"$group":{"_id":"$field","count":{"$sum":1}}}]}' | jq '.documents[]'
data-xxx with your Atlas app ID.