KeywordPurpose
bsonTypeSpecifies the BSON data type (string, int, bool, date, array, object, etc.)
requiredLists mandatory fields
propertiesDefines validation rules for each field
minimum / maximumNumeric range validation
minLength / maxLengthString length validation
patternValidates strings using a regular expression
enumRestricts a field to specific values

 Example:

db.createCollection("products", {
  validator: {
    $jsonSchema: {
      bsonType: "object",
      required: ["name", "price", "category"],
      properties: {
        name: {
          bsonType: "string",
          minLength: 3
        },
        price: {
          bsonType: "double",
          minimum: 0
        },
        category: {
          enum: ["Electronics", "Clothing", "Books"]
        },
        inStock: {
          bsonType: "bool"
        }
      }
    }
  }
});

Add in Existing Collection

db.runCommand({
  collMod: "employees",
  validator: {
    $jsonSchema: {
      bsonType: "object",
      required: ["name", "age", "department"],
      properties: {
        name: {
          bsonType: "string"
        },
        age: {
          bsonType: "int",
          minimum: 18
        },
        department: {
          bsonType: "string"
        }
      }
    }
  },
  validationLevel: "strict",
  validationAction: "error"
});