Unbounded Array

noun

say it: “un-BOWN-did uh-RAY” /ʌnˈbaʊndɪd əˈreɪ/

A list inside a database record that keeps growing without any limit, which makes the record slower and eventually too big.

What is an unbounded array?

An unbounded array is an array inside a document that never stops growing, such as every page view of a product. It makes the document slower to read and, in the end, too big to save, so those items belong in a collection of their own.

// Grows forever: one more entry inside the product per view
db.products.updateOne({ _id: 12 }, { $push: { views: { at: new Date() } } });
// Better: one small document per view, in its own collection
db.productViews.insertOne({ productId: 12, at: new Date() });

In a sentence

  • “Pushing every order into the customer document made an unbounded array.”
  • “The fix for the unbounded array was a views collection with one small document per view.”

Level: Journeyman · More MongoDB terms at this level

Updated