What is a MongoDB document schema?
A 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" }
});