Docs Home → Launch & Manage MongoDB → MongoDB Atlas
Edit Schema
On this page
Edit Schema Using the Atlas UI
To edit an existing schema, use the following steps.
In Atlas, go to the Clusters page for your project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
If the Clusters page is not already displayed, click Database in the sidebar.
Edit Schema Using the Atlas CLI
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.
Syntax
Parameters
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 |
NoteYou can provide a single document or an array of documents
in the | Required |
Output
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"
Examples
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.
Set Schema Example
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 }
Delete Schema Example
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 }