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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
namestring | 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. | ||||||||||||
typestring | Required. For MongoDB Atlas clusters, this value is always | ||||||||||||
config.clusterNamestring | Required. The name of the cluster in Atlas. | ||||||||||||
config.readPreferencestring | The read preference mode for queries sent through the service.
| ||||||||||||
config.wireProtocolEnabledBoolean | If |
Federated database instances
{ "name": "<Service Name>", "type": "datalake", "config": { "dataLakeName": "<Federated database instance name>" } }
Field | Description |
|---|---|
namestring | 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. |
typestring | Required. For a Federated database instance, this value is always |
config.dataLakeNamestring | 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 | |
|---|---|---|
refstring | A JSON schema | |
source_keystring | 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 | |
foreign_keystring | The name of the field in the foreign collection's schema that contains
the value referenced by | |
is_listBoolean | 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|
namestring | The name of the role. Role names identify and distinguish between roles in the same collection. Limited to 100 characters or fewer. | ||||||||
apply_whenobject | 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_filtersDocument 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.readobject?Default: undefined | An expression that specifies whether To maintain Sync compatibility, the expression must be defined and may only reference queryable fields. | ||||||||
document_filters.writeobject?Default: undefined | An expression that specifies whether To maintain Sync compatibility, the expression must be defined and may only reference queryable fields. | ||||||||
readobject?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 | ||||||||
writeobject?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 | ||||||||
insertobject?Default: true | An expression that evaluates to
App Services only evaluates this expression for insert operations and
only after determining that the role has | ||||||||
deleteobject?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 | ||||||||
searchBoolean Default: true | An expression that evaluates to true if the role has permission to search the collection using Atlas Search. ImportantApp Services performs | ||||||||
fieldsDocument 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>.readobject?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>.writeobject?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>.fieldsDocument Default: {} | A See the Field-level Permissions for Embedded Documents role pattern for more information. | ||||||||
additional_fieldsDocument Default: {} | A document that defines the role's field-level To maintain Sync compatibility, the
inner | ||||||||
additional_fields.readobject?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.writeobject?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 | |
|---|---|---|
namestring | Required. The name of the filter. Filter names are useful for identifying and distinguishing between filters. Limited to 100 characters or fewer. | |
apply_whenobject | 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 | |
queryobjectDefault: {} | A MongoDB query that App Services merges into a filtered operation's existing query. ExampleA filter withholds documents that have a | |
projectionobjectDefault: {} | 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 |