MongoDB Data Source Configuration Files
On this page
Note
This page describes a legacy configuration file format. You should
only use this information if you're using the deprecated
realm-cli
.
Any configuration files you pull with App Services CLI or export from the UI use the latest configuration version. For detailed information on the current configuration file format, see App Configuration.
app/ └── data_sources/ └── <service name>/ ├── config.json └── <database>/ └── <collection>/ ├── schema.json ├── relationships.json └── rules.json
Service Configuration
MongoDB Clusters
{ "name": "<Service Name>", "type": "mongodb-atlas", "config": { "clusterName": "<Atlas Cluster Name>", "readPreference": "<Read Preference>", "wireProtocolEnabled": <Boolean> } }
Field | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name String | Required. Default: The service name used to refer to the cluster within this Atlas App Services app. The name may be at most 64 characters long and must only contain ASCII letters, numbers, underscores, and hyphens. | ||||||||||||
type String | Required. For MongoDB Atlas clusters, this value is always "mongodb-atlas" . | ||||||||||||
config.clusterName String | Required. The name of the cluster in Atlas. | ||||||||||||
config.readPreference String | The read preference mode for queries sent through the service.
| ||||||||||||
config.wireProtocolEnabled Boolean | If true , clients may connect to the app over the MongoDB Wire
Protocol. |
Federated database instances
{ "name": "<Service Name>", "type": "datalake", "config": { "dataLakeName": "<Federated database instance name>" } }
Field | Description |
---|---|
name String | Required. Default: The service name used to refer to the Federated database instance within this App Services app. The name may be at most 64 characters long and must only contain ASCII letters, numbers, underscores, and hyphens. |
type String | Required. For a Federated database instance, this value is always "datalake" . |
config.dataLakeName String | Required. The name of the Federated database instance in Atlas. |
Databases & Collections
Collection Schema
If you want to enforce a schema for a collection, define a
schema.json
configuration file that contains a JSON schema for the
documents. The root level schema must be an object schema, which has the following form:
{ "title": "<Object Type Name>", "bsonType": "object", "properties": { "<Property Name>": { <Schema> }, ... } }
Relationships
{ "<Source Field Name>": { "ref": "#/relationship/<Data Source Name>/<Database Name>/<Collection Name>", "source_key": "<Source Field Name>", "foreign_key": "<Foreign Field Name>", "is_list": <Boolean> }, ... }
Field | Description | |
---|---|---|
ref String | A JSON schema
| |
source_key String | The name of the field in this collection's schema that specifies which
documents in the foreign collection to include in the relationship. A
foreign document is included if source_key contains the value of its
foreign_key field. | |
foreign_key String | The name of the field in the foreign collection's schema that contains
the value referenced by source_key . | |
is_list Boolean | If If |
Example
An ecommerce app defines a relationship between two collections: each
document in store.orders
references one or more documents in the
store.items
collection by including item _id
values in the order's
items
array. Both collection are in the same linked cluster
(mongodb-atlas
) and database (store
).
The relationship is defined for the orders
collection:
{ "items": { "ref": "#/relationship/mongodb-atlas/store/items", "source_key": "items", "foreign_key": "_id", "is_list": true } }
Default Rules
You can define default rules that apply to all collections in a data source that don't have more specific collection-level rules defined.
You define default rules in the data source's default_rule.json
configuration file at data_sources/<data-source-name>/default_rule.json
.
{ "roles": [<Role>], "filters": [<Filter>] }
Collection Rules
If the data source is not a Federated data source,
then you can define collection-level rules in a collection's rules.json
configuration file.
{ "database": "<Database Name>", "collection": "<Collection Name>", "roles": [<Role>], "filters": [<Filter>] }
Rule Configurations
Roles
{ "name": "<Role Name>", "apply_when": { Expression }, "document_filters": { "read": { Expression }, "write": { Expression } }, "read": { Expression }, "write": { Expression }, "insert": { Expression }, "delete": { Expression }, "search": <Boolean>, "fields": { "<Field Name>": { "read": { Expression }, "write": { Expression }, "fields": { Embedded Fields } }, ... }, "additional_fields": { "read": { Expression }, "write": { Expression } } }
Field | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
name string | The name of the role. Role names identify and distinguish between
roles in the same collection. Limited to 100 characters or fewer. | ||||||||
apply_when object | An expression that evaluates to true when this role applies to a user. When Device Sync (Flexible Mode) is not enabled, App Services assigns a role on a per-document basis. When Device Sync (Flexible Mode) is enabled, App Services assigns roles on a per-collection, per-session basis -- that is, for each synced collection when a client opens a sync connection. To assign a role, App Services evaluates the If Device Sync (Flexible Mode) is enabled, the assigned roles must be
Sync compatible. If the role is not Sync
compatible, but its | ||||||||
document_filters Document Default: undefined | A document with read and write expressions that determine whether the role's other permissions may be evaluated. If Device Sync is enabled, both If Device Sync is not enabled,
| ||||||||
document_filters.read object? Default: undefined | An expression that specifies whether To maintain Sync compatibility, the expression must be defined and may only reference queryable fields. | ||||||||
document_filters.write object? Default: undefined | An expression that specifies whether To maintain Sync compatibility, the expression must be defined and may only reference queryable fields. | ||||||||
read object? Default: undefined | An expression that evaluates to true if the role has permission to read all fields in the document. To maintain Sync compatibility, the
expression must be a boolean literal (either Document-level read permissions take priority over any field-level
permissions. If a role has document-level To define a default fallback alongside field-level rules, leave | ||||||||
write object? Default: undefined | An expression that evaluates to true if the role has permission to add, modify, or remove all fields in the document. To maintain Sync compatibility, the
expression must be a boolean literal (either Document-level write permissions take priority over any field-level
permissions. If a role has document-level To define a default fallback alongside field-level rules, leave You can use expansions like ImportantImplicit Read PermissionAny time a role has | ||||||||
insert object? Default: true | An expression that evaluates to
App Services only evaluates this expression for insert operations and
only after determining that the role has | ||||||||
delete object? Default: true | An expression that evaluates to true if the role has permission to delete a document from the collection. App Services only evaluates this expression for delete operations and
only after determining that the role has | ||||||||
search Boolean Default: true | An expression that evaluates to true if the role has permission to search the collection using Atlas Search. ImportantApp Services performs | ||||||||
fields Document Default: {} | A document where each key corresponds to a field name, and each value
defines the role's field-level To maintain Sync compatibility, the inner
NotePermission PriorityDocument-level | ||||||||
fields.<Field Name>.read object? Default: false | An expression that evaluates to true if the role has permission to read the field. To maintain Sync compatibility, the
expression must be a boolean literal (either | ||||||||
fields.<Field Name>.write object? Default: false | An expression that evaluates to true if the role has permission to add, modify, or remove the field. To maintain Sync compatibility, the
expression must be a boolean literal (either | ||||||||
fields.<Field Name>.fields Document Default: {} | A See the Field-level Permissions for Embedded Documents role pattern for more information. | ||||||||
additional_fields Document Default: {} | A document that defines the role's field-level To maintain Sync compatibility, the
inner
| ||||||||
additional_fields.read object? Default: false | An expression that evaluates to true if the
role has permission to read any field that does not have a field-level
permission definition in To maintain Sync compatibility, the
expression must be boolean (either | ||||||||
additional_fields.write object? Default: false | An expression that evaluates to true if the
role has permission to add, modify, or remove any field that does not
have a field-level permission definition in To maintain Sync compatibility, the
expression must be boolean (either |
Filters
{ "name": "<Filter Name>", "apply_when": { Expression }, "query": { MongoDB Query }, "projection": { MongoDB Projection } }
Field | Description | |
---|---|---|
name string | Required. The name of the filter. Filter names are
useful for identifying and distinguishing between filters.
Limited to 100 characters or fewer. | |
apply_when object | An expression that determines when this filter applies to an incoming MongoDB operation. ImportantAtlas App Services evaluates and applies filters before it reads any
documents, so you cannot use MongoDB document expansions in a filter's Apply When expression.
However, you can use other expansions like | |
query object Default: {} | A MongoDB query that App Services merges into a filtered operation's existing query. ExampleA filter withholds documents that have a
| |
projection object Default: {} | A MongoDB projection that App Services merges into a filtered operation's existing projection. ImportantProjection ConflictsMongoDB projections can be either inclusive or exclusive, i.e. they can either return only specified fields or withhold fields that are not specified. If multiple filters apply to a query, the filters must all specify the same type of projection, or the query will fail. ExampleA filter withholds the
|