Docs Menu
Docs Home
/
MongoDB Atlas
/ / /

Define and Manage Secrets

On this page

  • Define a Secret
  • View Secrets
  • Update a Secret
  • Use a Secret
  • Delete a Secret

A Secret is a private value that is stored on the Atlas backend and hidden from users. Secrets are useful for storing sensitive information such as an API key or an internal identifier.

You cannot directly read the value of a Secret after defining it. Instead, you link the Secret to another Value, then access the value from a Trigger Function.

You can define a new Secret from the UI or using the App Services CLI.

1
  1. Navigate to the Triggers page:

    1. If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.

    2. If it's not already displayed, select your project from the Projects menu in the navigation bar.

    3. In the sidebar, click Triggers under the Services heading.

      The Triggers page displays.

  2. Click the Linked App Service: Triggers link.

  3. In the sidebar, click Values under the Build heading.

  4. Click Create a Value.

2

Enter a name for the Secret. This name is how you refer to the Secret in Functions and must be unique within the project.

Note

Secret Name Restrictions

Value names cannot exceed 64 characters and may only contain ASCII letters, numbers, underscores, and hyphens. The first character must be a letter or number.

3
  1. Select Secret type.

  2. Enter the new Secret's value in the Add Content input box.

    Secret values may not exceed 500 characters.

Warning

You cannot directly read the value of a Secret after saving it.

4

After you've defined the Secret, click Save. If your application deployment drafts enabled, click Review & Deploy to deploy the changes.

1

Use your MongoDB Atlas Administration API Key to log in to the App Services CLI:

appservices login --api-key="<API KEY>" --private-api-key="<PRIVATE KEY>"
2

Run the following command to get a local copy of your configuration files:

appservices pull --remote=<App ID>

By default, the command pulls files into the current working directory. You can specify a directory path with the optional --local flag.

3

Run the following command to define a new Secret:

appservices secrets create --app=<Your App ID> \
--name="<Secret Name>" \
--value="<Secret Value>"
4

Run the following command to deploy your changes:

appservices push

You can view a list of all Secrets in an app from the UI or using the App Services CLI.

  1. From the Triggers page, click the Linked App Service: Triggers link.

  2. In the sidebar, click Values under the Build heading.

The table lists all Values, including Secrets, and indicates each Value's type in its row.

To list the names and IDs of all Secrets, run the following command:

appservices secrets list --app=<Your App ID>

You can update a Secret from the UI or using the App Services CLI.

To update a Secret from the Atlas UI:

  1. From the Triggers page, click the Linked App Service: Triggers link.

  2. In the sidebar, click Values under the Build heading.

  3. Find the Value that you want to update in the table, open its Actions menu, and select Edit Secret.

  4. You can change both the name and value for the Secret.

  5. Click Save and then, if needed, deploy your changes.

To update the value of a Secret using the App Services CLI, run the following command:

appservices secrets update --app=<Your App ID> \
--secret="<Secret ID or Name>" \
--name="<Updated Secret Name>" \
--value="<Updated Value>"

You cannot directly read the value of a Secret after defining it.

To use a Secret in a Triggers Function:

  1. Create a new Value that links to the Secret.

  2. Use the context.values module to access the Secret's value in your Function.

You can delete a Secret from the UI or using the App Services CLI.

To delete a Secret from the Atlas UI:

  1. From the Triggers page, click the Linked App Service: Triggers link.

  2. In the sidebar, click Values under the Build heading.

  3. Find the Value that you want to delete in the table, open its Actions menu, and select Delete Secret.

  4. Confirm that you want to delete the Secret.

To delete a Secret using the App Services CLI, run the following command:

appservices secrets delete --app=<Your App ID> --secret=<Secret ID>

Tip

You can delete multiple Secrets with a single command by specifying their name or id values as a comma-separated list.

appservices secrets delete --app=<Your App ID> \
--secret=some-api-key,609af850b78eca4a8db4303f,another-key

Back

Aggregate