Lesson 10 of 14
Polymorphic Schemas without Regret - 011
Oka collection lo different shapes unna documents pettodcha? Pettochu, kani query chesetappudu thala noppi raddadu ante ee pattern follow avvandi.
Core Explanation: Polymorphism (Storing different entities like 'Bikes', 'Cars' in 'Vehicles' collection) is powerful. Kani common fields ni common ga unchandi. Type specific fields ni sub-document lo pettandi leda attributes array vadeyandi. Lekapothe index create cheyyadam kastam.
Wrong Practice: Inconsistent field names for same purpose.
{ "type": "car", "car_color": "red" }
{ "type": "bike", "bike_colour": "black" } // 'colour' spelling diff + prefix
Querying all red vehicles is hard now.
Best Practice: Common structure + Attribute Pattern.
{
"type": "car",
"color": "red", // Common field
"specs": { "doors": 4 } // Specific
}
{
"type": "bike",
"color": "black",
"specs": { "cc": 150 }
}
Closing Insight: "Structure entha flexible unna, Query access patterns matram consistent ga maintain cheyyali."