Note
Legacy Page
This page describes the legacy configuration file format used by
realm-cli version 1. For an up-to-date description of Atlas App Services
configuration files, see App Configuration.
Overview
App Services uses JSON files and source code files to define and configure every component of an application. Each component has a specific configuration file schema and every application uses a standard file structure to organize the configuration files.
When Will I Use Configuration Files?
Every App is composed of a collection of configuration files, so you use application configuration files whenever you create or modify an App. If you use the App Services UI then you rarely deal directly with the configuration files themselves, but other deployment methods, like App Services CLI and GitHub allow you to define and edit the configuration files directly.
Directory Structure
The following figure shows a high-level view of an App's directory structure:
yourRealmApp/ ├── config.json ├── secrets.json ├── auth_providers/ │ └── <provider name>.json ├── functions/ │ └── <function name>/ │ ├── config.json │ └── source.js ├── services/ │ └── <service name>/ │ ├── config.json │ ├── incoming_webhooks/ │ │ ├── config.json │ │ └── source.js │ └── rules/ │ └── <rule name>.json ├── triggers/ │ └── <trigger name>.json ├── hosting/ │ ├── metadata.json │ └── files/ │ └── <files to host> └── values/ └── <value name>.json
Application Configuration
Application-level configuration information is defined in a single
document named config.json stored in your application's root
directory.
yourRealmApp/ └── config.json
Configuration
{ "app_id": "", "name": "", "security": { "allowed_request_origins": ["<Origin URL>"] }, "hosting": { "enabled": <boolean>, "custom_domain": "<Custom Domain Name>", "app_default_domain": "<Default Domain Name>" }, "custom_user_data_config": { "enabled": <Boolean> "mongo_service_id": "<MongoDB Service ID>", "database_name": "<Database Name>", "collection_name": "<Collection Name>", "user_id_field": "<Field Name>" } "deployment_model": "<Deployment Model Type>", "location": "<Deployment Cloud Region Name>", "config_version": <Version Number> }
Field | Description | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
app_idString | The application's App ID. | |||||||||||||||||||
nameString | The application's name. NoteApp Name LimitationsApplication names must be between 1 and 32 characters and may only contain ASCII letters, numbers, underscores, and hyphens. | |||||||||||||||||||
securityDocument | A document that contains configuration options for application-level security features.
| |||||||||||||||||||
hostingDocument | A document that contains configuration options for all hosted files:
| |||||||||||||||||||
config_versionNumber | The schema version that all configuration files in the application conform to. This value is machine generated and you typically should not manually set or modify it. | |||||||||||||||||||
custom_user_data_configDocument | A document that contains configuration options for custom user data.
| |||||||||||||||||||
deployment_modelString | The application's deployment model. The following values are valid:
| |||||||||||||||||||
locationString | The name of the cloud region that the application is deployed in.
|
Authentication Providers
Authentication providers
are defined in your application's /auth_providers
directory.
Each provider is defined in its own JSON file named after the provider. For detailed information on configuring and using a specific authentication provider, see that provider's reference page.
yourRealmApp/ └── auth_providers/ └── <provider name>.json
Configuration
{ "id": "<Provider ID>", "name": "<Provider Name>", "type": "<Provider Type>", "disabled": <Boolean>, "config": { "<Configuration Option>": <Configuration Value> }, "secret_config": { "<Configuration Option>": "<Secret Name>" }, "metadata_fields": [{ "required": <Boolean>, "name": "Field Name" }] }
Field | Description |
|---|---|
idString | A value that uniquely identifies the authentication provider. Atlas App Services automatically generates a unique ID for a provider when you create it. |
nameString | The name of the authentication provider. |
typeString | The type of the authentication provider. Valid Options:
|
configDocument | A document that contains configuration values that are specific to the authentication provider. The existence of this field and its exact configuration fields depend on the provider type. |
secret_configDocument | A document where each field name is a private configuration field for the provider and the value of each field is the name of a Secret that stores the configuration value. |
metadata_fieldsArray<Document> | An array of documents where each document defines a metadata field that describes the user. The existence of this field and the exact format of each metadata field document depends on the provider type. |
disabledBoolean | If |
Functions
Atlas Functions are defined in a sub-directory of your application's
/functions directory. Each function maps to its own subdirectory
with the same name as the function.
Each function is configured in config.json and has its source code
defined in source.js.
yourRealmApp/ └── functions/ └── <function name>/ ├── config.json └── source.js
Configuration
{ "id": "<Function ID>", "name": "<Function Name>", "private": <Boolean>, "can_evaluate": <Rule Expression>, "disable_arg_logs": <Boolean>, "run_as_system": <Boolean>, "run_as_user_id": "<App Services User ID>", "run_as_user_id_script_source": "<Function Source Code>" }
Field | Description |
|---|---|
idString | A value that uniquely identifies the function. App Services automatically generates a unique ID for a function when you create it. |
nameString | The name of the function. The name must be unique among all functions in your application. |
privateBoolean | If |
can_evaluateDocument | A rule expression that evaluates to |
disable_arg_logsBoolean | If |
run_as_systemBoolean | If |
run_as_user_idString | The unique ID of a App Services User that the
function always executes as. Cannot be used with
|
run_as_user_id_script_sourceString | A stringified function that runs whenever the
function is called and returns the unique ID of a App Services
User that the function executes as. Cannot be used with
|
Source Code
exports = function() { // function code };
MongoDB Services
Every MongoDB Atlas data source
linked to your app is configured as a service in the /services
directory. Each data source maps to its own sub-directory with the same
name as the service.
The primary service configuration for a MongoDB Atlas data source is
config.json, which defines connection parameters and sync rules.
If the data source is not a synced cluster or
Federated database instance, then you can
define collection-level rules in the /rules sub-directory.
yourRealmApp/ └── services/ └── <MongoDB Service Name>/ ├── config.json └── rules/ └── <rule name>.json
Important
MongoDB Service names are not necessarily the same as their linked
data source's name in Atlas. You define the service name for a data
source when you link it to your application. For linked clusters, the
default MongoDB service name is mongodb-atlas. For
Federated data sources, the default service name is
mongodb-datafederation.
Service Configuration
The configuration file to link an Atlas cluster should have the following form:
{ "id": "<Service ID>", "name": "<Service Name>", "type": "mongodb-atlas", "config": { "clusterName": "<Atlas Cluster Name>", "readPreference": "<Read Preference>", "wireProtocolEnabled": <Boolean>, "sync": <Sync Configuration> } }
The configuration file for a Federated data source should have the following form:
{ "id": "<Service ID>", "name": "<Service Name>", "type": "datalake", "config": { "dataLakeName": "<Federated database instance name>" } }
Exactly one of config.dataLakeName and config.clusterName is
required, depending on whether you are linking a cluster or a
Federated data source.
Field | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
idString | A string that uniquely identifies the service. App Services automatically generates a unique ID for a MongoDB service when you create it. | ||||||||||||
nameString | The name of the service. The name may be at most 64 characters
long and can only contain ASCII letters, numbers, underscores,
and hyphens. For clusters, the default name is | ||||||||||||
typeString | For MongoDB Atlas clusters, this value is always | ||||||||||||
config.clusterNameString | Required when linking a cluster. The name of the service's linked cluster in MongoDB Atlas. | ||||||||||||
config.dataLakeNameString | Required when linking a Federated data sources. The name of the instance that you want to link to your application. | ||||||||||||
config.readPreferenceString | The read preference mode for queries sent through the service. Not available for Federated data sources.
| ||||||||||||
config.syncDocument | A configuration document that determines if a cluster is synced and, if it is, defines the rules for sync operations on the cluster. Not available for Federated data sources. For detailed information on sync configuration documents, see Synced Cluster Configuration. |
Synced Cluster Configuration
The config.sync field of config.json determines if a cluster is
synced and, if it is, defines the rules for sync operations on
the cluster.
{ ..., "config": { ..., "sync": { "state": <Boolean>, "development_mode_enabled": <Boolean>, "database_name": "<Development Mode Database Name>", "partition": { "key": "<Partition Key Field Name>", "type": "<Partition Key Value Type>", "permissions": { "read": <JSON Expression>, "write": <JSON Expression> } } } } }
Field | Description |
|---|---|
sync.stateBoolean | If |
sync.development_mode_enabledBoolean | If |
sync.database_nameString | The name of the database in the synced cluster where App Services should store synced objects. When Development Mode is enabled, App Services stores synced objects in this database. Each object type maps to its own collection in the database with a schema that matches the synced objects. |
sync.partition.keyString | The name of the partition key field that maps data into individual synced realms. |
sync.partition.typeString | The type of the partition key field value. |
sync.partition.permissionsDocument | A document that defines the |
MongoDB Collection Rules (Non-Sync)
For non-synced clusters, you can define collection-level rules that App Services
evaluates dynamically for each request. Each collection's rules are stored in a
rules.json file in that collection's configuration subdirectory, which is
data_sources/<data-source-name>/<database-name>/<collection-name>/.
Note
Federated data sources do not support rules or schemas. You can only access a Federated data source from a system function.
{ "id": "<Rule ID>", "database": "<Database Name>", "collection": "<Collection Name>", "roles": [<Role>], "schema": <Document Schema>, "filters": [<Filter>], }
Field | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
idString | A string that uniquely identifies the trigger. App Services automatically generates a unique ID for a trigger when you create it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
databaseString | The name of the database that holds the collection. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
collectionString | The name of the collection. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rolesArray<Document> | An array of Role configuration documents, which have the following form:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schemaDocument | A document schema. The root level schema must be an object schema, which has the following form: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
filtersArray<Document> | An array of Filter configuration documents, which have the following form:
|
External Services
3rd party services are defined in the /services
directory. Each service maps to its own sub-directory with the same name as the
service.
Each service directory contains the following:
config.json: a service configuration file/rules: a sub-directory of service rule configurations/incoming_webhooks: a sub-directory of webhook configurations (if the service supports webhooks, i.e. HTTP, GitHub, or Twilio)
yourRealmApp/ └── services/ └── <services name>/ ├── config.json ├── incoming_webhooks/ │ ├── config.json │ └── source.js └── rules/ └── <rule name>.json
Service Configuration
{ "id": "<Service ID>", "name": "<Service Name>", "type": "<Service Type>", "config": { "<Configuration Option>": <Configuration Value> }, "secret_config": { "<Configuration Option>": "<Secret Name>" }, }
Field | Description |
|---|---|
idString | A string that uniquely identifies the service. Atlas App Services automatically generates a unique ID for a service when you create it. |
nameString | The name of the service. The name may be at most 64 characters long and can only contain ASCII letters, numbers, underscores, and hyphens. |
typeString | The type of the service. Valid Options:
|
configDocument | A document with fields that map to additional configuration
options for the service. The exact configuration fields depend on
the service |
secret_configDocument | A document where each field name is a private configuration field for the service and the value of each field is the name of a Secret that stores the configuration value. |
Service Rules
Rules for a specific external service are defined in the /<service
name>/rules sub-directory.
Each rule maps to its own JSON file with the same name as the rule.
{ "id": "<Rule ID>", "name": "<Rule Name>", "actions": ["<Service Action Name>"], "when": <JSON Rule Expression> }
Field | Description |
|---|---|
idString | A string that uniquely identifies the rule. App Services automatically generates a unique ID for a rule when you create it. |
nameString | The name of the service rule. The name may be at most 64 characters long and can only contain ASCII letters, numbers, underscores, and hyphens. |
actionsArray<String> | A list of service actions that the rule applies to. The specific
actions available depend on the service |
whenDocument | A rule expression that evaluates to |
Incoming Webhooks
Incoming webhooks for a specific service are defined in the
/<service name>/incoming_webhooks/ sub-directory.
Incoming webhooks use the same configuration format as function but have additional configuration parameters.
Configuration
{ "id": "<Function ID>", "name": "<Function Name>", "private": <Boolean>, "can_evaluate": <Rule Expression>, "disable_arg_logs": <Boolean>, "run_as_system": <Boolean>, "run_as_user_id": "<App Services User ID>", "run_as_user_id_script_source": "<Function Source Code>", "respond_result": <Boolean>, "options": { "httpMethod": "<HTTP Method>", "validationMethod": "<Webhook Validation Method>", "secret": "<Webhook Secret>" } }
Field | Description | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
idString | A value that uniquely identifies the function. App Services automatically generates a unique ID for a function when you create it. | |||||||||||||
nameString | The name of the function. The name must be unique among all functions in your application. | |||||||||||||
privateBoolean | If | |||||||||||||
can_evaluateDocument | A rule expression that evaluates to | |||||||||||||
disable_arg_logsBoolean | If | |||||||||||||
run_as_systemBoolean | If | |||||||||||||
run_as_user_idString | The unique ID of a App Services User that the
function always executes as. Cannot be used with
| |||||||||||||
run_as_user_id_script_sourceString | A stringified function that runs whenever the
webhook is called and returns the unique ID of a App Services
User that the function executes as. Cannot be used with
| |||||||||||||
respond_resultBoolean | If | |||||||||||||
optionsDocument | A document that contains configuration options for the webhook.
|
Source Code
exports = function() { // webhook function code };
Triggers
Triggers are defined in your application's
/triggers directory.
Each trigger is defined in its own JSON file with the same name as the trigger.
yourRealmApp/ └── triggers/ └── <trigger name>.json
Configuration
{ "id": "<Trigger ID>", "name": "<Trigger Name>", "type": "<Trigger Type>", "function_name": "<Trigger Function Name>", "config": { "<Configuration Option>": <Configuration Value> }, "disabled": <Boolean>, }
Field | Description |
|---|---|
idString | A string that uniquely identifies the Trigger. Atlas App Services automatically generates a unique ID for a trigger when you create it. |
nameString | The name of the Trigger. The name may be at most 64 characters long and can only contain ASCII letters, numbers, underscores, and hyphens. |
typeString | The type of application event that the trigger listens for. Valid Options:
|
function_nameString | The name of the Atlas Function that the Trigger
executes whenever it fires. The Trigger automatically passes
arguments to the function depending on the Trigger |
configDocument | A document with fields that map to additional configuration
options for the trigger. The exact configuration fields depend on
the trigger |
disabledBoolean | If |
Hosting
Files that you want to host on Atlas App Services should be
included in your application's /hosting directory. Each file will be
uploaded with the metadata defined in metadata.json.
You can configure the metadata
for each hosted file in metadata.json. This metadata configuration
file is an array of documents that each correspond to a single hosted
file's metadata attributes.
yourRealmApp/ └── hosting/ ├── metadata.json └── files/ └── <files to host>
Metadata Configuration
[ { "path": "<File Resource Path>", "attrs": [{ "name": "<Attribute Type>", "value": "<Attribute Value>" }] } ]
Field | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
pathString | The resource path of the file. | ||||||||||
attrsArray<Document> | An array of documents where each document represents a single metadata attribute. Attribute documents have the following form: Metadata Attribute Document
|
Note
If you do not specify a Content-Type metadata attribute for a hosted
file, Atlas App Services will attempt to automatically add a Content-Type
attribute to it based on the file extension.
For example, App Services would automatically add the attribute
Content-Type: application/html to the file myPage.html.
Values
Values are defined in your application's /values directory.
Each value is defined in its own JSON file named after the value.
yourRealmApp/ └── values/ └── <value name>.json
Configuration
{ "id": "<Value ID>", "name": "<Value Name>", "from_secret": <boolean>, "value": <Stored JSON Value|Secret Name> }
Field | Description |
|---|---|
idString | A string that uniquely identifies the value. Atlas App Services automatically generates a unique ID for a value when you create it. |
nameString | A unique name for the value. This name is how you refer to the value in functions and rules. |
from_secretBoolean | Default: |
valueString, Array, or Object | The stored data that App Services exposes when the value is referenced. If If |