I’m working on software for my business, and due to inexperience with Mongo I’m wondering what the best way to structure the data required to add a new feature.
Basically right now there is a paginated table of all of our products. There’s some search filters, you can put the product code and it appears on the list.
Problem is, some products have many different codes. 1 product might have 5+ alternate codes (aside from the “main” one)… I need to figure out the best way to add multiple codes to each product, and still have the search filters return the “parent” product.
For example, Product A might have main code “1234”. Product A might have alternate codes “5678” and “9012”. If someone searches for “5678”, I need Product A to appear in search results.
I know one easy way to do this, would be to have “code” be an array on my Product object, but when I was learning Meteor/Mongo, I remember reading that any variables that will need to be searched should NOT be nested inside another variable for performance reasons. Code is going to be the primary search field…
I also know I could have a 2nd collection that will contain a list of every “Code” and which parent product they belong to. Problem with this method is, it doesn’t play nicely with the pagination table. The table uses the Pages package and for the filters & sortability, relies on the data inside the Product collection itself.
Any ideas on how I could add these additional Codes to my paginated results from the Product collection, without neglecting performance?