Nodelay Heehoo
Nodelay Heehoo

Reputation: 63

mongodb document structure - limitation and performance advice needed

I'm designing the structure of a mongodb document, which contains an array of objects as one of the attributes:

{ _id : xxx, someObjectAttribute : { ... }, someArrayAttribute : [ { timeStamp: yyy, value: zzz } , ... ] }

It's envisioned that 'someArrayAttribute' above may need to hold millions of elements, each with the same structure of {timeStamp, value}, and on which aggregations and filtrations will be done (e.g., sum of values over a time period).

I would like to get advice on:

Thanks in advance, I'd be glad to clarify anything.

Upvotes: 0

Views: 52

Answers (1)

Sammaye
Sammaye

Reputation: 43884

that 'someArrayAttribute' above may need to hold millions of elements,

Nope, won't work.

A document is limited by 16MB of space. Millions will not fit into that so with just considering that:

Whether the above structure is plausible for the said volume of elements, and if there are obvious design weaknesses for performance

No

The maximum number of elements 'someArrayAttribute' can possibly contain

Much less, more like 12,000 with very small objects but even then you will get performance problems working on such a large array unless you split it down into chunks within the document.

Whether a better structure than above can make use of mongodb's built-in aggregations

The only real structure you can have is the parent document in one collection and the someArrayAttribute split out into a separate collection.

You could, I suppose, house chunks of someArrayAttribute within documents within another collection or even the same collection but that sounds tedious and precariously complicated.

Upvotes: 1

Related Questions