View Schema Using the Atlas UI
In Atlas, go to your federated database instance for your project.
WARNING: Navigation Improvements In Progress
We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview documentation.
If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.
If it's not already displayed, select your project from the Projects menu in the navigation bar.
In the sidebar, click Data Federation under the Services heading.
The Data Federation page displays.
View Schema Using mongosh
The sqlGetSchema command retrieves the schema stored for
the specified collection or view.
Syntax
db.getSiblingDB("<dbName>").runCommand({ sqlGetSchema: "<collection-name>|<view-name>" })
Parameters
Parameter | Type | Description | Necessity |
|---|---|---|---|
| string | Name of the collection for which to retrieve the schema. Either the collection name or view name is required. | Conditional |
| string | Name of the view for which to retrieve the schema. Either the view name or collection name is required. | Conditional |
Output
The command returns the following output if the collection or view does not have a schema.
{ "ok" : 1, "metadata" : { }, "schema" : { } }
The command returns output similar to the following if the collection or view has a schema.
{ "ok": 1, "metadata": { "description": "<description>" }, "schema": { "version": NumberLong(1), "jsonSchema": {} } }
The metadata.description field describes how the schema was set
for the collection. Value can be one of the following:
generated automatically by Atlas Data FederationIndicates that the schema was automatically generated by Atlas Data Federation.
set using sqlGenerateSchema with setSchemas = trueIndicates that the schema was set by the Create Schema Using
mongoshcommand because thesetSchemaoption was set totrue.
set using sqlSetSchemaIndicates that the schema was set using the Edit Schema Using
mongoshcommand.
The schema document contains the following fields:
Parameter | Type | Description |
|---|---|---|
| integer | Format version of the schema. Value is always 1. |
| document | JSON schema of the collection or view. The JSON schema can contain the following fields :
To learn more about these fields, see JSON Schema Keywords. |
Example
Consider a collection named egData in a database named
sampleDB with the following documents:
{"a": {"b": {"c": [1, 2, 3]}}, "s": 1} {"a": {"b": {"c": [4, 5, 6]}}, "s": 2} {"a": {"b": [7, 8, 9]}, "s": 3} {"a": {"b": {"c": []}}, "s": 4} {"a": {"b": {"c": "hello"}}, "s": 5} {"a": {"b": {"c": {"d": 1}}}, "s": 6} {"a": {"b": {"c": null}}} {"s": 7}
The following command retrieves the schema stored for the egData
collection:
db.getSiblingDB("sampleDB").runCommand({ sqlGetSchema: "egData" })
The previous command returns the following output. For more information on the fields in the output, see Output.
{ "ok" : 1, "metadata" : { "description" : "set using sqlGenerateSchema with setSchemas = true" }, "schema" : { "version" : NumberLong(1), "jsonSchema" : { "bsonType" : [ "object" ], "properties" : { "a" : { "bsonType" : [ "object" ], "properties" : { "b" : { "bsonType" : [ "object", "array" ], "properties" : { "c" : { "bsonType" : [ "array", "string", "object", "null" ], "properties" : { "d" : { "bsonType" : [ "int" ] } }, "items" : { "bsonType" : [ "int" ] } } }, "items" : { "bsonType" : [ "int" ] } } } }, "s" : { "bsonType" : [ "int", "object" ] } } } } }