I've to store line items in the database.
Currently, I'm creating a batch of them and storing it as a single document.
date: null,
items: [
{ name: 'Bla', cost: 5, ref: 'user id' },
{ name: 'Bla', cost: 5, ref: 'user id' },
]
But I'm having a gut feeling that it will be more costly (performance and processing) because it is an array of object. ($unwind, $project).
Will it be good if I store each line item as a document instead?
The reason why I've not done so far is we may have around 1 billion documents in 1-3 years.
Once more thing, how can I generate a unique ID for each line item? I know Mongo generates _id, but I mean a number 0, 1, 2, etc. which can be shown in invoices.
So, I'm not sure if MongoDB can handle it effectively.
Best, Faheem
EDIT:
These are the reasons that I think this question is not a duplicate to the suggested duplicates.
Those questions are referring to ref vs embedding the document. I'm not.
The question is what will be the best way (in terms of performance and low latency) to store inline items, in a batch (array of object) or as a single document. I'm not concerned about references or anything here.