Q65 [Scenario]: An e-commerce system sells products with vastly different attributes (e.g., Laptops have CPU/RAM, Clothing has Size/Color). How do you model this?
Apply the Polymorphic Pattern alongside the Attribute Pattern. Store common fields (title, price, category) at top level, and store variant attributes inside a key-value array: attributes: [{ k: 'size', v: 'XL' }, { k: 'color', v: 'Red' }]. Index the array with a compound multikey index on { 'attributes.k': 1, 'attributes.v': 1 }.
Key Takeaways
- The Attribute Pattern organizes varying product properties cleanly.
- Compound multikey index
{ 'attributes.k': 1, 'attributes.v': 1 }targets variable product specs.
Knowledge Check
Which design pattern organizes diverse product specification fields into key-value array objects for indexability?