Should I use two collections or one?


Hi! I’m relatively new to meteor and full stack dev and I’m trying to understand a simple issue about how to keep my data in the server. So I’m building an app and defining a model for it, the main structure object has a lot of data inside of it plus a label name eg

collection = { label: ‘mylabel’, data: [{a lot of data}] }

So I want to list the labels and then display the data on demand…

What would be better for this? should I keep the labels in a separate collection that fetches the data from a second collection by a relational id OR is it ok to just have one collection of large objects and query for the labels or fields as I need them?



MongoDB isn’t relational and I don’t think you’d gain much by keeping a separate collection for labels since they’re just strings anyways. It would complicate your code in having to hack together joins.

Unless you have a specific optomization need for this use case I would keep this in a single collection as it keeps the code simpler. To start I’d just hack something like this StackOverflow article and not even worry about performance.

Later if needed you can optimize if and only if you need to with indexes (Demo of _ensureIndex) and querying on the server if you need access to the entire list of labels.