Set up Data Schema
Using the web console (opens in a new tab), navigate to the Schema
section in the side menu, select people
from the collections list, then click +
in the top right corner.
In this example, we are defining a schema for the people
collection, which dictates that the document must be an object and should include required fields for name
(with a data type of string) and age
(with a data type of number).
{
type: "object",
required: ["name", "age"],
properties: {
name: { type: "string" },
age: { type: "number" }
}
}
You can copy & paste the schema object above to the popped-up textarea and hit Add
.
With the defined schema, you cannot add a document that violates the schema requirements. For example:
set {name:123,age:"Bob"} people Bob