How to deploy the MongoDB Atlas Boilerplate

The MongoDB Atlas Boilerplate allows you to deploy an application integrated with MongoDB Atlas on the edge. Besides, due to the integration with the Atlas Data API, you’re able to create, retrieve, update, and delete items in your collections through standard HTTPS requests.

By using Azion Edge Platform to run your database project, your digital data and assets benefit from edge computing capabilities, including faster delivery, lower latency, and enhanced security.


Requirements

Before using this template, you need to:

You need to activate these modules via Azion Console. To do so:

  1. Access Azion Console > Account menu
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for each module.

Getting the template

To get the MongoDB Atlas Boilerplate, access Azion Console and click the + Create button on the homepage.

This will open a modal where you can select Templates > MongoDB Atlas Boilerplate card.


Setting up the template

In the configuration form, you must provide the information to configure your application. Fill in the presented fields.

Fields identified with an asterisk are mandatory.

  1. Connect Azion with your GitHub account.
  • A pop-up window will open to confirm the installation of the Azion GitHub App, a tool that connects your GitHub account with Azion’s platform.
  • Define your permissions and repository access as desired.
  1. Select the Git Scope to work with.
  2. Fill in the fields:
  • Application Name *: the name of your edge application on Azion.
    • The bucket for storage and the edge function will use the same name.
    • Use a unique and easy-to-remember name. If the name has already been used, the platform returns an error message.
  • Atlas API Token *: the token to authorize the connection with the AtlasData API.
  • Atlas API URL *: the assigned URL endpoint to connect with Atlas Data API.
  • Collection Name *: the name of a created collection in the specified database.
  • Database Name *: the name of the created database in the MongoDB Atlas data source.
  • dataSource Name *: the name of the created MongoDB Atlas data source or cluster.
  1. Click the Deploy button to start the deployment process.

During the deployment, you’ll be able to follow the process through a window showing off the logs. When it’s complete, the page shows information about the application and some options to continue your journey.

Key configurations

By deploying this template, the script creates:

  • An edge application to run your project and manage all your settings.
  • An Azion domain to access your edge application. You can also set up a custom domain to run on this edge application.
  • An edge function containing custom logic.
  • A GitHub repository for your project. The repository includes a GitHub Action that guarantees a continuous deployment workflow.

The execution of this template also includes integration with Mongo DB Atlas and Atlas Data API, acting as a middleware to manage and access your database.


HTTPS requests examples

The integration with the Atlas Data API enables you to access the data using standard HTTPS requests. Acting as a middleware to access and manage your data, the API sits between your cluster and the client requests.

You’re able to create, retrieve, update, and delete items in your collections through any tools that allow you to send standard HTTPS requests, such as your terminal or Postman.

The API has dedicated endpoints according to the operation you want to complete.

Finding a document

Terminal window
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/findOne" \
-X POST \
-H "apiKey: $API_KEY" \
-H 'Content-Type: application/ejson' \
-H "Accept: application/json" \
-d '{
"dataSource": "my-datasource",
"database": "my-database-azion",
"collection": "template",
"filter": {
"text": "Do the dishes"
}
}'

Where:

VariableRequiredTypeDescription
dataSourceYesStringThe name of your data source or cluster
databaseYesStringThe name of the database in the data source
collectionYesStringThe name of a created collection in the specified database
filterYesObjectA query operator to filter the documents

Inserting a document

Terminal window
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/insertOne" \
-X POST \
-H "apiKey: $API_KEY" \
-H 'Content-Type: application/ejson' \
-H "Accept: application/json" \
-d '{
"dataSource": "my-datasource",
"database": "my-database-azion",
"collection": "template",
"document": {
"status": "open",
"text": "Do the dishes"
}
}'
Where:
| Variable | Required | Type | Description |
|---|---|---|---|
| `dataSource` | Yes | String | The name of your data source or cluster |
| `database` | Yes | String | The name of the database in the data source |
| `collection` | Yes | String | The name of a created collection in the specified database |
| `document` | Yes | Object | The document to insert into the collection |
#### Updating a document
```bash
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/updateOne" \
-X POST \
-H "apiKey: $API_KEY" \
-H 'Content-Type: application/ejson' \
-H "Accept: application/json" \
-d '{
"dataSource": "my-datasource",
"database": "my-database-azion",
"collection": "template",
"filter": {
"_id": { "$oid": "64224f4d089104f1766116a5" }
},
"update": {
"$set": {
"status": "complete",
"completedAt": { "$date": { "$numberLong": "1680105272788" } }
}
}
}'
Where:
| Variable | Required | Type | Description |
|---|---|---|---|
| `dataSource` | Yes | String | The name of your data source or cluster |
| `database` | Yes | String | The name of the database in the data source |
| `collection` | Yes | String | The name of a created collection in the specified database |
| `filter` | Yes | Object | A query operator to filter the documents |
| `update` | Yes | Object | An update expression to apply to matching documents |
#### Deleting a document
```bash
curl -s "https://data.mongodb-api.com/app/$CLIENT_APP_ID/endpoint/data/v1/action/deleteOne" \
-X POST \
-H "apiKey: $API_KEY" \
-H 'Content-Type: application/ejson' \
-H "Accept: application/json" \
-d '{
"dataSource": "my-datasource",
"database": "my-database-azion",
"collection": "template",
"filter": {
"_id": { "$oid": "64224f3cd79f54ad342dd9b2" }
}
}'

Where:

VariableRequiredTypeDescription
dataSourceYesStringThe name of your data source or cluster
databaseYesStringThe name of the database in the data source
collectionYesStringThe name of a created collection in the specified database
filterNoObjectA query operator to filter the documents

All the requests return a response in JSON or EJSON format, including the information according to the status code: 200 Success, 400 Bad Request, and 401 Unauthorized.


Managing the template

Considering that this initial setup may not be optimal for your specific edge application, all settings can be customized any time you need by using Azion Console.

To manage and edit your edge application’s settings, proceed as follows:

  1. Access Console.
  2. On the upper-left corner, select Products menu > Edge Application.
  • You’ll be redirected to the Edge Application page. It lists all the edge applications you’ve created.
  1. Find the edge application related to your template and select it.
  • The list is organized alphabetically. You can also use the search bar located in the upper-left corner of the list; currently, it filters only by Application Name.

After selecting the edge application you’ll work on, you’ll be directed to a page containing all the settings you can configure.

Adding a custom domain

The edge application created during the deployment has an assigned Azion domain to make it accessible through the browser. The domain has the following format: xxxxxxxxxx.map.azionedge.net/. However, you can add a custom domain for users to access your edge application through it.

go to Domains reference

Contributors