Docs Home → Atlas App Services
Data Model Mapping
On this page
Overview
This page contains information on how the App Services Schema used by Atlas Device Sync maps to the Realm Object Schema used by the Realm SDKs.
To generate Realm SDK Schemas from your App Services Schemas, refer to Generate SDK Object Models. To generate App Services Schemas from Realm SDK client code, refer to Development Mode.
To learn more about how Device Sync uses these two schemas, refer to the Sync Data Model Overview.
Mappings
Type Name
The title
field contains the name of the object type represented by
the schema. This is equivalent to a class or schema name in a Realm SDK.
The type name must be unique among all schemas in your synced cluster
but is otherwise arbitrary and does not need to match the collection
name.
A conventional approach is to name each object type with a singular noun, like "Dog" or "Person". Schemas generated in development mode or by sampling existing documents use this convention.
Property Types
You can configure the following constraints for a given property:
Parameter | Type | Description |
---|---|---|
Type | String | Every property in a Realm Object Schema has a strongly defined data type. A property's type can be a primitive data type or an object type defined in the same Realm Object Schema. The type also specifies whether the property contains a single value or a list of values. Realm Database supports the following property types:
For more information on supported data types, refer to Schema Types. |
Optional | Boolean | Optional properties may contain a null value or be entirely
omitted from an object. By default, all properties are optional
unless explicitly marked as required. |
Default | Boolean | If a client application creates a new object that does not have a value for a defined property, the object uses the default value instead. When you attempt to create an object that is missing a value for a required field, it fails validation and does not persist to the realm. |
Indexed | Boolean | A property index significantly increases the speed of certain
read operations at the cost of additional overhead for write
operations. Indexes are particularly useful for equality
comparison, such as querying for an object based on the value of
a property. However, indexes consume additional storage. |
Realm SDK data type documentation:
Array Properties
Both Realm Object Schemas and App Services Schemas support array properties.
You can find information on using array data types in the Realm SDK documentation on defining a Realm Object Schema.
For more information on modeling array properties in an App Services Schema, refer to BSON Types - Array. App Services Schemas support certain constraints that Realm Object Schemas do not, such as specifying the minimum and maximum number of items.
Embedded Objects
Embedded objects are embedded as nested data inside of a parent object. An embedded object inherits the lifecycle of its parent object. It cannot exist as an independent Realm object.
Realm SDK embedded object documentation:
For more information on modeling to-one relationships in an App Services Schema, refer to Embedded Object Relationships.
Sets
Realm Object Schemas and App Services Schemas both support the Set data type. A set is a collection of unique values.
Realm SDK Set documentation:
For more information on modeling sets in an App Services Schema, refer to Set.
Dictionaries
Realm Object Schemas and App Services Schemas both support the Dictionary data type. A set is a collection of unique values. A dictionary is a collection of dynamic and unique string keys paired with values of a given type. A dictionary is functionally an object or document without pre-defined field names.
Realm SDK dictionary documentation:
For more information on modeling dictionaries in an App Services Schema, refer to Dictionary.
Relationships
Realm Object Schemas support the following types of relationships:
To-one relationships: A to-one relationship means that an object is related in a specific way to no more than one other object.
To-many relationships: A to-many relationship means that an object is related in a specific way to multiple objects.
Inverse relationships: An inverse relationship links an object back to any other objects that refer to it in a defined to-one or to-many relationship.
App Services Schemas support to-one and to-many relationships. App Services Schemas do not support inverse relationships.
Realm SDK relationship documentation:
For more information on modeling relationships in an App Services Schema, refer to Relationships.
Example
This example shows how to model a Dog
with Device Sync.
App Services Schema
This App Services Schema creates the Dog
data model used by Device Sync.
{ "title": "Dog", "bsonType": "object", "required": [ "_id", "_partition", "name" ], "properties": { "_id": { "bsonType": "objectId" }, "_partition": { "bsonType": "string" }, "name": { "bsonType": "string" }, "age": { "bsonType": "int" } "breed": { "bsonType": "string" } } }
Realm Object Schema
The following code examples create the Dog
Realm Object Schema in each of the
Realm SDKs.
Data in Atlas
An application using Device Sync for the Dog
data model creates MongoDB documents
in Atlas that looks like the following example.
{ "_id": ObjectId('616f44305a205add93ff1081'), "age": 8, "breed": "Golden Retriever", "name": "Jasper" }