Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB Atlas

Schema Management

On this page

  • Manage Schemas
  • JSON Schema Format
  • Supported JSON Schema Fields

Atlas SQL schemas are JSON schemas that describe data as it exists in MongoDB, including its polymorphism, sparseness, and nested, structured data. Atlas Data Federation can automatically generate a schema by sampling data from documents in your collection or view. Atlas SQL schemas are necessary when connecting SQL-based tools to Atlas data sources.

Atlas SQL leverages Atlas Data Federation as its query engine. Configure Atlas SQL schemas on the federated database level.

After creating a SQL Connection, verify that an Atlas SQL schema is in place. For Quick Start Atlas SQL set up, Atlas Data Federation automatically generates a schema by sampling data from documents in your collection or view. For advanced configuration set up of Atlas SQL, generate an Atlas SQL for any Atlas Data Federation collection you wish to analyze from a SQL-based tool.

Atlas Data Federation automatically generates a schema for a collection or view in the storage configuration when you:

  • Create the collection or view in the storage configuration.

  • Rename a collection or view that does not already have a schema. If you rename a collection or view that already has a schema, the schema is also renamed. Atlas Data Federation does not generate a new schema for a renamed collection or view if it already exists.

  • Set the storage configuration.

In addition, for wildcard (*) collections, Atlas Data Federation generates a schema when it discovers the collections in the namespace catalog for the wildcard (*) collections.

You can manually generate schemas for all collections and views, set or schedule updates for schemas, and view stored schemas using the UI or CLI. You can also schedule recurring schema updates.

You can manually delete a schema for a collection or view by running the Edit Schema Using the Atlas CLI command with an empty schema document. Data Federation automatically removes the schema for a collection or view when you:

In addition, for a wildcard (*) collection, Atlas Data Federation deletes the schema when it discovers that the collection has been removed from the namespace catalog.

The schema for a collection is a document with two fields: jsonSchema and version.

"schema" : {
"version" : NumberLong(1),
"jsonSchema" : <JSON Schema object>
}

The version field represents the version of the schema format that the document uses. The value is always 1. The jsonSchema field is a document that describes the schema of the namespace.

Atlas SQL supports the following JSON schema fields:

  • bsonType

  • items

  • properties

  • additionalProperties

  • required

Note

You can provide a single document or an array of documents for the items field. When you retrieve the schema, the items field shows the form that you used for setting the schema.

To learn more about these fields, see JSON Schema Keywords.

← Query with Atlas SQL Statements