Hi @Pavel_Duchovny thank you again. I realized I posted on the wrong question… Btw, after analyzing the one-to-many relation using embedded array, I realized that Im very limited in sorting. As you suggested, I can extend the document of aliments with a new document for that user (is the the outlier?). But what happen if the user wants to sort by lets say, amount of kcal?
The user will access his Aliment “portfolio” in the aliment section and it is presented with the list of aliment in alphabetical order (paged). The records shown are just a projection of the name and the id of the aliment and when the user clicks on it, the details are shown (nutritional values) (maybe I dont even need to project the name). Now, the user may want to sort according to lets say the amount of proteins or filter based on tags the user can add to the aliment.
At this point, isnt better to go back to a Aliment per document? (I would just move the count of the aliments n a separate document and use that to regulate the number) If that is the case, I was thinking to use the aggregation framework and do:
1. Match on userId
2. Project the needed values (if filter by tags, then tags id and name of aliment) (if filter by name, it will be a text search)
3. Match the values with the filter
4. Use the skip and limit for pagination
This aggregation should first filter using the userId and then text search or tags.contains will be used right? (Im trying to avoid scanning documents of other users)
I know that skip is not efficient… and I know it can be done with last key, but this should work only on indexed fields that are ordered?
About the version, im referring to concurrency version, but, again, since Aliments are private to a single user, I should not need this.
To be honest, embedding and extending the document makes sense, given the privacy of the aliment. But Im concerned with read performance. Also, Aliment will be used by other entities in the application, but only copied.
At first I was also concerned with write performance, because with embedded I need to extract all everytime I made a change, but extending the array of aliment to multiple document looks very nice.