Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrlynn/a58110cd668e45076cd0c3848cdaee4a to your computer and use it in GitHub Desktop.
Save mrlynn/a58110cd668e45076cd0c3848cdaee4a to your computer and use it in GitHub Desktop.
Examples for MongoDB Atlas Data API Video
ENDPOINT
--------
https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta
API KEY
--------
0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/insertOne \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database" : "household",
"collection" : "pets",
"document" : { "name": "Harvest",
"breed": "Labrador",
"age": 5 }
}'
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/findOne \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database" : "household",
"collection" : "pets",
"filter" : {"name" : "Harvest" }
}'
Postman
---------
https://tinyurl.com/atlasdapi
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/insertMany \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database": "household",
"collection": "pets",
"documents": [{
"name": "Brea",
"breed": "Labrador",
"age": 9,
"colour": "black"
},
{
"name": "Bramble",
"breed": "Labrador",
"age": 1,
"colour": "black"
}
]
}'
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/find \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database": "household",
"collection": "pets",
"filter": { "breed": "Labrador",
"age": { "$gt" : 2} },
"sort": { "age": 1 } }
'
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/updateOne \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database": "household",
"collection": "pets",
"filter" : { "name" : "Harvest"},
"update" : { "$set" : { "colour": "yellow" }}
}'
curl https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta/action/aggregate \
-H 'Content-Type: application/json' \
-H 'api-key: 0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj' \
--data-raw \
'{
"dataSource": "Cluster0",
"database": "household",
"collection": "pets",
"pipeline" : [ { "$match": {"breed": "Labrador"}},
{ "$group": { "_id" : "$colour",
"count" : { "$sum" : 1},
"average_age": {"$avg": "$age" }}}]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment