1 · MongoDB · WHY IS THIS NECESSARY?
Three items with different sets of characteristics
In a relational table
In the document collection
items
id name type damage crit heal block
1 Blade of Dawn weapon 45 0.15 NULL NULL
2 Small Healing Potion NULL NULL 120 NULL
3 Dawn Shield shield NULL NULL NULL 30
{ _id: 1, type: "weapon", damage: 45, crit_chance: 0.15, name: "Клинок зари" }
{ _id: 2, type: "potion", heal_amount: 120, name: "Малое лечение"}
{ _id: 3, type: "shield", block: 30, name: "Щит зари"}
The rule “potions have heal, no damage”
is written as CHECK. Subtypes with PK = FK are also valid.
Option 3: EAV
Option 4: jsonb
Question about the slide
Table (id, attribute, value).
Queries based on attributes become more complex.
The jsonb Column in PostgreSQL: CHECK, GIN, and Expression-Based Indexes.
If Option 4 works, why do we need a separate database?