Docs Menu

Atlas Device Sync Configuration Files

On this page

  • Partition-Based Sync Configuration
  • Flexible Sync Configuration

You can configure Atlas Device Sync for your application in the sync directory:

app/
└── sync/
└── config.json

When you use Partition-Based Sync, your App Services app uses this Sync configuration:

sync/config.json
{
"state": <"enabled" | "disabled">,
"development_mode_enabled": <Boolean>,
"service_name": "<Data Source Name>",
"database_name": "<Development Mode Database Name>",
"partition": {
"key": "<Partition Key Field Name>",
"type": "<Partition Key Type>",
"permissions": {
"read": { <JSON Expression> },
"write": { <JSON Expression> }
}
},
"last_disabled": <Number>,
"client_max_offline_days": <Number>
}
Field
Description
state
String

The current state of the sync protocol for the application.

Valid Options:

  • "enabled"
  • "disabled"
service_name
String
The name of the MongoDB data source to sync. You cannot use sync with a serverless instance or data lake.
development_mode_enabled
Boolean
If true, Development Mode is enabled for the application. While enabled, App Services automatically stores synced objects in a specific database (specified in database_name) and mirrors objects types in that database's collection schemas.
database_name
String
The name of a database in the synced cluster where App Services stores data in Development Mode. App Services automatically generates a schema for each synced type and maps each object type to a collection within the database.
partition.key
String
The field name of your app's partition key. This field must be defined in the schema for object types that you want to sync.
partition.type
String

The value type of the partition key field. This must match the type defined in the object schema.

Valid Options:

  • "string"
  • "objectId"
  • "long"
partition.permissions.read
JSON Expression
An expression that evaluates to true when a user has permission to read objects in a partition. If the expression evaluates to false, App Services does not allow the user to read an object or its properties.
partition.permissions.write
JSON Expression
An expression that evaluates to true when a user has permission to write objects in a partition. If the expression evaluates to false, App Services does not allow the user to modify an object or its properties. Write permission requires read permission. A user cannot write to a document that they cannot read.
last_disabled
Number
The date and time that sync was last paused or disabled, represented by the number of seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).
client_max_offline_days
Number
Controls how long the backend compaction process waits before aggressively pruning metadata that some clients require to synchronize from an old version of a realm.

When you use Flexible Sync, your App uses this Sync configuration:

sync/config.json
{
"type": "flexible",
"development_mode_enabled": <Boolean>,
"service_name": "<Data Source Name>",
"database_name": "<Development Mode Database Name>",
"state": <"enabled" | "disabled">,
"permissions": {
"rules": {
"<Collection Name>": [
{
"name": <String>,
"applyWhen": { <JSON Expression> },
"read": { <JSON Expression> },
"write": { <JSON Expression> }
}
]
},
"defaultRoles": [
{
"name": <String>,
"applyWhen": { <JSON Expression> },
"read": <JSON Expression>,
"write": <JSON Expression>
}
]
},
"queryable_fields_names": [
<Array of String Field Names>
]
}
Field
Description
type
String

The Sync Mode for the application.

Valid Options:

  • "flexible"
development_mode_enabled
Boolean
If true, Development Mode is enabled for the application. While enabled, App Services automatically stores synced objects in a specific database (specified in database_name) and mirrors objects types in that database's collection schemas.
service_name
String
The name of the Atlas cluster data source to sync. You cannot use sync with a serverless instance.
database_name
String
The name of a database in the synced cluster where App Services stores data in Development Mode. App Services automatically generates a schema for each synced type and maps each object type to a collection within the database.
state
String

The current state of the Sync protocol for the application.

Valid Options:

  • "enabled"
  • "disabled"
permissions.rules.<Coll>
String
You can define rules that apply to a single collection by specifying the collection name. App Services apps apply rules in order from the beginning of the array, so start with the most specific rules first.
rules.<Coll>.name
String
The name of the specific rule in the rules array. You might use a descriptive name to make it easier to parse the rules, such as "adminReadWrite" or "employeeReadOnly".
rules.<Coll>.applyWhen
JSON Expression
An expression that evaluates to true when the rule should be applied. An example might be {"%%user.custom_data.isGlobalAdmin": true}. This reads the value of the isGlobalAdmin bool from the user's custom data, and applies the rule when the value of this bool is true.
rules.<Coll>.read
JSON Expression
An expression that evaluates to true when a user has permission to read objects in the collection. If the expression evaluates to false, App Services does not allow the user to read an object or its properties.
rules.<Coll>.write
JSON Expression
An expression that evaluates to true when a user has permission to write objects in the collection. If the expression evaluates to false, App Services does not allow the user to modify an object or its properties. Write permission requires read permission. A user cannot write to a document that they cannot read.
permissions.defaultRoles
String

Your App evaluates defaultRoles after rules. If no collection-specific rule applies to a user's attempt to access data through an App, App Services proceeds to evaluate defaultRoles until it finds a set of permissions that apply to the user. This may occur when a collection does not have a specific set of rules defined, or when none of the rules defined for a collection apply to a user.

You can have more than one defaultRole, and they apply across all the collections that your App can access, even when you have more specific collection rules defined.

defaultRoles.name
String
The name of the specific role in the defaultRoles array. You might use a descriptive name to make it easier to parse the roles, such as "adminReadWrite" or "employeeReadOnly".
defaultRoles.applyWhen
JSON Expression
An expression that evaluates to true when the role should be applied. An example might be {"%%user.custom_data.isGlobalAdmin": true}. This reads the value of the isGlobalAdmin bool from the user's custom data, and applies the role when the value of this bool is true.
defaultRoles.read
JSON Expression
An expression that evaluates to true when a user has permission to read objects in the collection. If the expression evaluates to false, App Services does not allow the user to read an object or its properties.
defaultRoles.write
JSON Expression
An expression that evaluates to true when a user has permission to write objects in the collection. If the expression evaluates to false, App Services does not allow the user to modify an object or its properties.
queryable_fields_names
Array of Strings
The names of the fields that your client application can query to determine which data to synchronize.
last_disabled
Number
The date and time that sync was last paused or disabled, represented by the number of seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).
client_max_offline_days
Number
Controls how long the backend compaction process waits before aggressively pruning metadata that some clients require to synchronize from an old version of a realm.
←  MongoDB Data Source Configuration FilesFunction Configuration Files →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.