---
title: "Create a schema"
method: POST
path: "/groups/{groupId}/apps/{appId}/schemas"
tags: ["schemas"]
---

# Create a schema

`POST /groups/{groupId}/apps/{appId}/schemas`

Define a new [schema](https://www.mongodb.com/docs/atlas/app-services/schemas) 
for a linked collection. When creating a schema with this endpoint, 
ensure that the JSON payload is completely unescaped. Incorrectly 
escaped JSON formats can lead to errors.

## Request body

- object
  - `metadata` SchemaMetadata, required — Metadata that describes which linked collection the schema applies to.
    - `data_source` string — The data source name.
    - `database` string — The database name.
    - `collection` string — The collection name.
  - `schema` SchemaDefinition — A valid [schema](https://www.mongodb.com/docs/atlas/app-services/schemas) for the collection.
    - `bsonType` 'object' | 'array' | 'string' | 'number' | 'int' | 'long' | 'double' | 'decimal' | 'date' | 'timestamp' | 'bool' | 'null' | 'regex' | 'objectId' | 'binary' | 'uuid' | 'function' | 'javascript' | 'symbol' | 'minKey' | 'maxKey' — The [BSON type](https://www.mongodb.com/docs/atlas/app-services/schemas/types/#std-label-schema-types) of the field.
    - `title` string — A human-readable title for the schema.
    - `required` string[] — For `object` schemas, an array of field names that are required in instances of the object.
    - `properties` object — An object where each field name is a property in the schema. The corresponding value is a [schema](https://www.mongodb.com/docs/atlas/app-services/schemas/types/#std-label-schema-types) definition for that field.
  - `relationships` SchemaRelationships — Relationships to foreign collections. Each field name is a property in the schema. The corresponding value is a [relationship](https://www.mongodb.com/docs/atlas/app-services/schemas/relationships/) definition for that field.

## Response `200`

Ok

- SchemaMetadataInstance
  - `_id` string, required
  - `metadata` SchemaMetadata, required — Metadata that describes which linked collection the schema applies to.
    - `data_source` string — The data source name.
    - `database` string — The database name.
    - `collection` string — The collection name.

---

[API](https://skmtc.net/mongodb/apis/mongodb-atlas-app-services-admin-api.md) · [All operations](https://skmtc.net/mongodb/apis/mongodb-atlas-app-services-admin-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/mongodb/mongodb-atlas-app-services-admin-api/revisions/1365ab72bc03/schema)
