Docs Menu
Docs Home
/
MongoDB Atlas
/ / /

Edit Schema

On this page

  • Edit Schema Using the Atlas UI
  • In Atlas, go to the Clusters page for your project.
  • Navigate to Manage SQL Schemas page.
  • Edit schema.
  • Edit Schema Using the Atlas CLI
  • Syntax
  • Parameters
  • Output
  • Examples
  • Set Schema Example
  • Delete Schema Example

To edit an existing schema, use the following steps.

1
  1. If it's not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

  3. If the Clusters page is not already displayed, click Database in the sidebar.

2

From the Data Federation menu, click Manage SQL Schemas.

3
  1. Next to a schema, click the .

  2. Edit the JSON.

  3. Click Save.

The sqlSetSchema command sets or deletes the schema for a collection or view. The command uses the provided schema to create the relational schema. The command doesn't validate the schema provided with the command against the data in the collection.

db.runCommand({
sqlSetSchema: "<collection-name>|<view-name>",
schema: {
"version": 1,
"jsonSchema": <jsonSchema>
}
})
db.runCommand({
sqlSetSchema: "<collection-name>|<view-name>",
schema: {}
})
Parameter
Type
Description
Necessity
<collection-name>
string
Name of the collection for which to set the schema. You must provide either a collection name or a view name.
Conditional
<view-name>
string
Name of the view for which to set the schema. You must provide either a view name or a collection name.
Conditional
schema
document
The format version of the schema and either:
  • the JSON schema for the collection or view

  • an empty document to remove the schema for the collection or view.

Note

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

Required

The command returns the following output if it succeeds.

{ "ok" : 1 }

You can verify that the command succeeded by running the sqlGetSchema command. The metadata.description field in the response contains the following value:

"set using sqlSetSchema"

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 examples below use the sqlSetSchema command to set and remove schema for the above collection.

The following sqlSetSchema command sets the schema for the egData collection.

db.runCommand({
sqlSetSchema : "egData",
"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" ],
"properties" : {
"b" : {
"bsonType" : [ "object" ],
"properties" : {
"c" : {
"bsonType" : [ "object" ],
"properties" : {
"d" : {
"bsonType" : [ "array" ],
"items" : {
"bsonType" : [ "string" ]
}
}
}
}
}
}
}
}
}
}
}
})

The previous command returns the following output.

{ "ok" : 1 }

The following sqlSetSchema command removes the schema for the egData collection.

db.runCommand({
sqlSetSchema: "egData",
schema: {}
})

The previous command returns the following output.

{ "ok" : 1 }

Back

View

Next

Schedule Updates