For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Define and Access Values

A Value is a named reference to a piece of static data stored by Atlas that you can access in Atlas Functions. Values provide an alternative to hardcoding configuration constants directly into your Functions.

In other words, Values allow you to separate deployment-specific configuration data from the business logic of your app.

Values can resolve to two types of data:

  • Plain text: Resolves to a regular JSON object, array, or string Value that you define.

  • Secret: Resolves to a Secret Value that you define.

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

1
  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 Streaming Data heading.

The Triggers page displays.

2
  1. Click the Linked App Service: Triggers link.

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

  3. Click Create a Value.

3

Enter a unique Value Name. This name is how you refer to the Value in Functions.

Note

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

4
  1. Select the Value type.

  2. Define either a plain text value or link to a Secret value:

    • To define a plain text value, Custom Content and enter the plain text Value in the input box.

    • To link to an existing Secret's value, select Link to Secret and select the Secret from the dropdown.

    • To link to a new Secret value, select Link to Secret, then enter the new Secret's name and the new Secret's value in the input box that appears.

    For more information on creating a Secret, see Create a Secret.

5

After you have named and defined the new Value, click Save.

Once saved, you can immediately access the Value in your Functions.

You can access a Value's stored data from an Atlas Function using the context.values module.

context.values.get("<Value Name>")

For example, the following Function returns true when the active user's id is included in the plain text array Value adminUsers:

Example Function that uses a Value
exports = function() {
const adminUsers = context.values.get("adminUsers");
const isAdminUser = adminUsers.indexOf(context.user.id) > 0;
return isAdminUser;
}
Rate this page