How to deploy the MongoDB Atlas Boilerplate

Preview

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.


Before using this template, you need to:

You must also activate:

Edge Functions
Application Acceleration

You need to activate these modules via Real-Time Manager (RTM). To do so:

  1. Access Real-Time Manager (RTM) > Account menu
  2. Select the Billing & Subscriptions option.
  3. Select the Subscriptions tab.
  4. Activate the switch for each module.

To get MongoDB Atlas Boilerplate, access Real-Time Manager (RTM) and select the Start with a template option on the homepage.

This will open a new page where you can select the MongoDB Atlas Boilerplate card.


Once you’re in the template’s page, click the Settings tab to open the configuration form and provide the information to configure your application.

Fields identified with an asterisk are mandatory.

  • Application Name *: the name of your edge application on Azion.
  • GitHub Personal Token *: your GitHub personal token.
  • 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.

After completing all the information, click the Next button, located in the bottom-right corner, to start the deployment.


During the deployment, you’ll be able to follow the process through a window showing off the logs. When it’s complete, the deployment page appears, confirming the edge application has been successfully created.

This page shows you the following sections:

  • Access your Edge Application section includes the link to visit and explore your edge application.
  • Build Summary contains the application’s name and function.
  • The Deployment details tab can be opened to access the logs related to the deployment.
  • What do you want to do next? provides recommendations regarding advanced options to enhance your edge application: Customize Domain, Manage Edge Application, View Edge Application Metrics, View Edge Application Logs, and the Back to Home button.

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, by being activated, 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.


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.

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
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.


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 RTM.

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

  1. Access RTM.
  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.

Once the template is deployed, you can also edit and update your args and code, as well as implement a continuous deployment workflow. However, you’ll need first to declare secrets on your project’s GitHub repository to complete the second build with the changes. When the second build is completed, you’ll be able to manage your project with a continuous deployment workflow and edit the args as desired.

To do so, open your new MongoDB Atlas Boilerplate repository on GitHub. Then, go to Settings > Secrets and variables > Action to add your variables, following these instructions:

  1. Add the Azion personal token to the secrets:
Terminal window
AZION_PERSONAL_TOKEN=<value>
  1. Add the environments that’ll be used in the action workflow in the main.yml file, included in the .github/workflows folder of your repository:
.github/workflows/main.yml
- name: edge-...
id: azion_edge
...
with:
....
azionPersonalToken: ${{ secrets.AZION_PERSONAL_TOKEN }}
....
  1. Open a pull request to merge the changes to the main branch and start the automatic deployment.

Now, your project is ready to work with a continuous deployment workflow, instantly updating any changes in the application or the repository.

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