I have several enums that need to be defined and shared between collections.
A practical example:
- There are X colors available "Light Blue", "Red", "Purple"....
- people can like items of several colors
- items can use several colors
I need to be able to change name of color "Red" to "Cherry Red" and all the associations need to be kept. I also need to expose these via an API as values not as enum ID's. There are several internal "queries" that work with enum ID's well (most). There are number of similar properties (less than 20)
The straight forward approach I can think of:
- have a collection to store {_id, color_name }
- people/items collection have an array of colors that stores ids
- when exposing people / items - an additional aggregation will get the color names and replace them in the array (fairly rare operation)
- when computing "which people may like this item's colors" I can use ids ( common operation)
Another approach would be to use directly color names, and use a transaction to update the color name everywhere (this is a rare operation but it happens)
I'm concerned about the speed of computing "which people like this item's colors" when using names directly.
I'm more experienced with RDBMS (probably shows in my first approach).
Questions:
- which of the 2 approaches would be more appropriate for a NoSQL database ?
- is there a speed penalty using strings versus object ids versus numeric ids for indexing ?
- is there another (better) approach that I'm missing ?
Edit: the analogy is imperfect, even if "Red" and "Cherry Red" in reality would be different, my requirements make them the same, think of someone evaluating the color and puts "Red" there and someone else with a better knowledge revises the document and says it's not "Red" that's "Cherry Red". ... well not everywhere, but in all users likes and in products that are still on the assembly line so to speak of.