Lesson 14 of 14
Why Unbounded Arrays are Time Bombs - 010
Mee array size 'ippudu takkuve kada' ani lite teesukunnara? 6 months tarwata ade array mee server ni crash chestundi.
Core Explanation: Array size perugutunte, document size perugutundi. Okka element push chesina, MongoDB entire document ni disk lo re-write cheyalsi ravochu (if it outgrows allocated space). Plus, indexing arrays creates multi-key indexes. Antha pedda array ni index chesthe, index bloat confirm.
Wrong Practice: Storing logs or history in an array.
// Audit Log in User Doc
{
"username": "pavan",
"activity_log": [ ...keeps growing forever... ]
}
Best Practice: Outlier Pattern or Separate Collection.
// Move logs to separate collection
db.logs.insert({ "user_id": "pavan", "activity": "login" })
Or Limit the array slice:
$push: { activity_log: { $each: [newItem], $slice: -10 } } // Keep only last 10
Closing Insight: "Arrays ki eppudu clear 'Max Limit' undali. Unlimited array = Future outage."