Values are named constants that you can use in MongoDB Stitch functions and rules. To access a value in functions, use the context.values variable. To access a value in rules, use the %%values expansion.

Define Values

In the MongoDB Stitch console,


Go to Values.

Under the Control section in the left-hand navigation bar, click Values.


Click New Value and enter a name for the new value in the New Value Name box.


Enter a value in the box below New Value Name.

The value must be a string, an array, or a valid JSON document. The following are all examples of valid values:

Name Value
publicStatus "Public"
adminUsers ["589a86bcfc57bd5c25c51de8", "629a82befc57bd5c20a51ed7"]
   "email": "",
   "phone": "+1-111-111-1111"

(Optional) Enable Private mode to prevent MongoDB Stitch client applications from accessing the value.

Private values may be accessed only by incoming webhooks, rules, and named functions.

Usage Examples

To access a value in rule or function expressions, use the %%values expansion. The examples use the values defined in the Define Values section.

Values in Stitch Rules

For example, you might specify a MongoDB service write rule where a field is writable if the authenticated user is one of the users defined in the value adminUsers:

{ "%%user.idHex": { "%in": "%%values.adminUsers" } }

Values in Stitch Functions

Values in Stitch functions are accessible through the context.values variable. The following example shows retrieving the value for the name test.

exports = function() {
    return context.values.get("test");

See also