Junior
From PDF
SQL
SQL & Databases
What is a MongoDB document schema?
document schema defines the structure, rules, and validations for documents in a
collection. MongoDB is schema-less by default, but you can enforce schema validation rules
using MongoDB schema validation.
Example:
db.createCollection("users", {
validator: {
$jsonSchema: {
bsonType: "object",
required: ["name", "email"],
properties: {
name: { bsonType: "string" },
email: { bsonType: "string" }
}
}
}
});
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png