The MongoDB Atlas Data API in Preview was also released in November 2021 to use with a hosted MongoDB instance through the company's Atlas offering. It lets you send complex queries and aggregations to MongoDB over a standard HTTPS interface, though it isn't currently recommended for direct client-side access.
For instance, once a cluster is created and the Data API is enabled for it, the following request can be used to insert a document -
curl --request POST \
'https://data.mongodb-api.com/app/<Unique ID>/endpoint/data/beta/action/insertOne' \
--header 'Content-Type: application/json' \
--header 'Access-Control-Request-Headers: *' \
--header 'api-key: <Data API Key>' \
--data-raw '{
"dataSource": "Cluster0",
"database": "todo",
"collection": "tasks",
"document": {
"status": "open",
"text": "Do the dishes"
}
}'
and the following to do an aggregation -
curl --location --request POST 'https://data.mongodb-api.com/app/<Unique ID>/endpoint/v1/beta/action/aggregate' \
--header 'Content-Type: application/json' \
--header 'Access-Control-Request-Headers: *' \
--header 'api-key:<Data API Key>' \
--data-raw '{
"collection":"movies",
"database":"sample_mflix",
"dataSource": "Cluster0",
"pipeline": [
{
"$search": {
"index": "default",
"text": {
"query": "Brad Pitt",
"path": {
"wilcard": "*"
}
}
}
}
]
}
Both the API and Atlas offer free tiers and only take a few minutes to spin up.
Full disclosure - I work for MongoDB, Inc.