Docs Home → Atlas App Services
Schema Types
On this page
All Schema Types
The following fields are available for all BSON schemas regardless of type:
{ "bsonType": "<BSON Type>" | ["<BSON Type>", ...], "type": "<JSON Type>" | ["<JSON Type>", ...], "enum": [<Value 1>, <Value 2>, ...], "description": "<Descriptive Text>, "title": "<Short Description>" }
Field Name | Description |
---|---|
bsonType | The BSON type of the property the schema describes. If the
property's value can be of multiple types, specify an array of
BSON types. Cannot be used with the BSON types include all JSON types as well as additional types that you can reference by name:
|
type | The JSON type of the property the schema describes. If the
property's value can be of multiple types, specify an array of
JSON types. Cannot be used with ImportantAtlas App Services supports the The following standard JSON types are available:
NoteMongoDB's JSON Schema implementation does not support the
|
enum | An array that includes all valid values for the data that the
schema describes. |
title | A short title or name for the data that the schema models. This
field is used for metadata purposes only and has no impact on
schema validation. |
description | A detailed description of the data that the schema models. This
field is used for metadata purposes only and has no impact on
schema validation. |
BSON Types
Array
An array
contains multiple values of a specific type. BSON array
schemas
use the standard JSON Schema array
format.
{ "bsonType": "array", "items": <Schema Document> | [<Schema Document>, ...], "additionalItems": <boolean> | <Schema Document>, "maxItems": <integer>, "minItems": <integer>, "uniqueItems": <boolean> }
Field Name | Description |
---|---|
items | A schema for all array items, or an array of schemas where
order matters. |
additionalItems | Default: If If the value is a schema object, any additional fields must validate against the schema. NoteThe |
maxItems | The maximum length of the array. |
minItems | The minimum length of the array. |
uniqueItems | Default: If TipUnique Arrays are SetsTo model a Set, use the |
Boolean
A bool
is either true
or false
.
{ "bsonType": "bool" }
Mixed
A mixed
field may contain any schema type except for arrays, embedded objects,
sets, and dictionaries. App Services does not enforce a consistent type across
documents, so two different documents may have values of different types.
Mixed fields can represent relationships. Sync translates these relationships to MongoDB as a DBRef to preserve the database name, collection name, and primary key of the link.
{ "bsonType": "mixed" }
Number
A number
generically configures some type of number. BSON schemas extend
JSON Schema numerics
with additional types to define integers, floats, and decimals.
{ "bsonType": "number" | "int" | "long" | "double" | "decimal", "multipleOf": <number>, "maximum": <number>, "exclusiveMaximum": <boolean>, "minimum": <number>, "exclusiveMinimum": <boolean> }
Field Name | Description |
---|---|
multipleOf | An integer divisor of the field value. For example, if
multipleOf is set to 3 , 6 is a valid value but
7 is not. |
maximum | The maximum value of the number. |
exclusiveMaximum | Default: If |
minimum | The minimum value of the number. |
exclusiveMinimum | Default: If |
Object
An object
is a structured object with string
keys that each have a typed
value. Objects represent Realm objects and embedded objects in synced realms as
well as the documents they map to in MongoDB.
{ "bsonType": "object", "title": "<Type Name>", "required": ["<Required Field Name>", ...], "properties": { "<Field Name>": <Schema Document> }, "minProperties": <integer>, "maxProperties": <integer>, "patternProperties": { "<Field Name Regex>": <Schema Document> }, "additionalProperties": <boolean> | <Schema Document>, "dependencies": { "<Field Name>": <Schema Document> | ["<Field Name>", ...] } }
Field Name | Description |
---|---|
required | An array of field names that must be included in the document. |
title | A type name for the object. App Services uses this value to name
the document's type in the GraphQL API. |
properties | An object where each field maps to a field in the parent
object by name. The value of each field is a schema document
that configures the value of the field. |
minProperties | The minimum number of fields allowed in the object. |
maxProperties | The maximum number of fields allowed in the object. |
patternProperties | An object where each field is a regular expression string that
maps to all fields in the parent object that match. The value
of each field is a schema document that configures the value
of matched fields. |
additionalProperties | Default: If If the value is a schema object, any additional fields must validate against the schema. |
dependencies | Specify property and schema dependencies. |
Note
Model Dictionaries With the object Schema Type
To model dictionaries, use
the object
schema type with additionalProperties
set to
the object type of the values stored in the dictionary.
ObjectId
An objectId
is a 12-byte identifier for BSON objects. ObjectId values are most commonly used as the
unique _id
values of documents in a MongoDB collection or objects in a
synced realm.
{ "bsonType": "objectId" }
String
A string
is text encoded as a series of characters. BSON string
schemas
use the standard JSON Schema string
format.
{ "bsonType": "string", "maxLength": <integer>, "minLength": <integer>, "pattern": "<Regular Expression>" }
Field Name | Description |
---|---|
maxLength | The maximum number of characters in the string. |
minLength | The minimum number of characters in the string. |
pattern | A regular expression string that must match the string value. |
UUID
A uuid
(Universal Unique Identifier) is a standardized
16-byte unique object identifier.
{ "bsonType": "uuid" }
Binary Data
A binData
is a piece of unstructured binary data. Maps to the binary
BSON type. Always uses subtype 0.
{ "bsonType": "binData" }
Realm Database Types
Set
A set is a collection of unique values.
A set schema is an array
schema where uniqueItems
is set to true
.
{ "bsonType": "array", "uniqueItems": true, "items": { "bsonType": "long" } }
Dictionary
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.
A dictionary schema is an object
schema where properties
is not defined
and the value of additionalProperties
is a schema for the dictionary value's
type.
Dictionary of a BSON Type
To store a dictionary with values of a BSON type, set additionalProperties
to the type's schema.
{ "bsonType": "object", "additionalProperties": { "bsonType": "string" } } }
Dictionary of Mixed BSON Types
To store a dictionary with mixed values, set
additionalProperties
to true
:
{ "bsonType": "object", "additionalProperties": true } }
Alternatively, you can define a full mixed
schema:
{ "bsonType": "object", "additionalProperties": { "bsonType": "mixed" } } }
Dictionary of Embedded Objects
To store a dictionary with embedded object values, define an object
schema
with the title
field set to the embedded object's type name:
{ "bsonType": "object", "additionalProperties": { "bsonType": "object", "title": “Address”, "properties": { "streetNumber": { "bsonType": "string" }, "street": { "bsonType": "string" }, "city": { "bsonType": "string" }, "province": { "bsonType": "string" }, "country": { "bsonType": "string" }, "postalCode": { "bsonType": "string" } } } }