Some rules of thumb that I found useful are as follows:
If there is only one logical copy of part of the information, it should be in one document (for example, if you have comments on the message, the easiest way is to include them in the message)
If you denormalize the data on SQL ground in some other table to avoid joining and something else, then the same behavior applies to the document repository: denormalize from one "main" place in the copy to other places. Copies should be considered as copies, not source information, so they can be overwritten by future denormalization actions.
If you need to access a canonical dataset, such as a user account, from multiple locations, store the links as ObjectId in mongodb, then run the second query for the linked document. You should know in your application that the second request is not a union, and will not block both documents to ensure consistency, therefore there may be inconsistencies in the results.
Essentially, you should think that your database is consistent at the document level. Any request for related documents can be inconsistent, so if you need consistency, you can denormalize this data into one document.
If you need a user account that will exactly match your comments, you will have to copy the relevant information next to your comments while writing the comments in the document. This means that you must constantly think about application-level consistency. If not, then, as I suspect, this is just a question for the user.
If you are concerned about performance when requesting data for all users participating in your page, I would recommend copying some data from the user account next to the comment, but only reading from this copy - you should write to your original user accounts.
This is all that comes to mind now, but I can edit, since everything happens to me :)
Matt
source share