Define a Data Model
Overview
Your App's data model is a description of the data that your App uses. Your data model ensures that your data complies with a specific structure, contains only valid values, and only changes in ways that you expect.
A data model consists of several components, including:
A set of declarative schemas that describe your App's data types.
A set of relationships that define logical connections between your schema.
A set of static values that you can use to define global constants, environment values, and secret values.
A set of rule-based query filters that you can use to dynamically limit MongoDB operations to a subset of all data for a given request.
Defining your App's data model is a key part of configuring and using Device Sync. You don't need to define a data model to use other App Services. However, a data model unlocks many powerful features that can save you time and let you focus on building features instead of writing boilerplate code.
For example, once you define a data model, you can automatically generate syncable Device SDK object models in your native programming language using an App administration tool. To learn more, see Generate SDK Object Models.
Document Schemas
A document schema is a JSON object that defines the structure of a particular type of data that your App uses. Document schemas describe which fields a document has, the type of values those fields contain, and conditions that must be met for a change of value to be valid.
You define schemas at the collection level. This means that you associate each schema with a particular MongoDB collection that holds the documents of that type. Schemas use a superset of the JSON schema standard that includes support for MongoDB's built-in BSON types, which allows you to fully describe your data in MongoDB.
Your App enforces schemas at runtime whenever data is written to MongoDB. This includes inserts, updates, and deletes from an API service, Function, or Device Sync.
To learn more, see Schemas.
Relationships
A relationship is a connection between two document schemas that lets you logically associate one document with zero or more other documents.
In a relationship, a "source" document stores a reference to related
documents, for example a list of related document _id
values. When
you use Device Sync, App Services automatically resolves the references to the
related documents so you can query them directly.
To learn more, see Relationships.
Values & Secrets
A value is a named constant that you can access by name in various ways throughout your App. For example, you can use a value to define the base URL of an external API service and then reference the value instead of duplicating the base URL across many Function definitions.
You can also define an environment value, which can change depending on your App's environment tag. For example, you might use a different API base URL in your development and production environments.
For sensitive information like API keys, you can define a named Secret value. Secret values are never directly exposed after you define them. Instead, you reference them by name in configuration files and rule expressions.
To learn more, see Values & Secrets.
Query Filters
A query filter constrains read and write operations on a data source to a subset of all of the data it contains. Query filters are standard MongoDB query and projection objects that are automatically concatenated to operations before they're sent to the data source.
Filters are dynamic and can apply different conditions based on which user ran the operations or other execution information. Adding a filter to a collection allows you to contextually limit access and can improve query performance for large data sets.
To learn more, see Filter Incoming Queries.