Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Some rules of thumb that I have found useful are this:</p> <ul> <li><p>If there is only one logical copy of a piece of information, it should be in one document (for example, if you have comments on a post, the simplest method is to embed them in the post)</p></li> <li><p>If you would denormalize data in SQL land into some other table to avoid joins and whatnot, the same behavior applies in document storage: denormalize from one "main" location into copies in other locations. The copies should be thought of as copies, and not origin information, so they can be overwritten with future denormalization actions.</p></li> <li><p>If you have to access one canonical set of data, like a user account, from multiple locations, store references as <code>ObjectId</code>s in mongodb, then execute a second query for the related document. You <em>must</em> be aware in your <em>application</em> that the second query is not a join, and will not lock both documents to ensure consistency, so there may be inconsistencies in the results.</p></li> </ul> <p>Essentially, you should think of your database as <em>consistent at the document level</em>. Any query of related documents may be inconsistent, so if you need consistency, you can denormalize that data into one document. </p> <p>If you <em>need</em> the user account to be <em>exactly</em> consistent with your comments, you will have to copy the relevant information next to your comments at the same time that you write the comments into the document. This means you have to think about consistency at the application level, all the time. If not, as I suspect is the case, just issue another query for the user.</p> <p>If you are concerned about performance in querying for data on all of the users that participate in your page, I would recommend copying over some data from the user account next to the comment, but only read from this copy - you should <em>write</em> to your original user accounts.</p> <p>That's all that comes to mind for now, but I may edit as things occur to me :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload