1 · MongoDB · SCHEMA
run
Without a diagram, there won't be any mistakes
If the diagram is saved to the database
db.item_configs.insertOne({
nmae: "Топор", // опечатка
type: "waepon", // опечатка
base_price: "сто" // строка вместо числа
})
validator: { $jsonSchema: {
required: ["name","type","base_price"],
properties: {
type: { enum: ["weapon","potion","shield"] },
base_price: { bsonType: "int", minimum: 0 }
}}}
// 100 → int: принят; Double(100) → код 121
validationLevel
validationAction
createIndex unique
strict: Check all inserts and updates.
moderate: Skip updates that are no longer valid.
off: Does not check anything
error — reject (code 121).
warn — skip, write to the server log.
_id is unique by default. The uniqueness of name is an explicit index: { name: 1 }, unique; a duplicate will result in error code 11000.
Three different mechanisms. None of them have external keys.
▶ P10: Migration