Normalization is just a method of organization to minimize repetition of data. It has nothing to do with efficiency of operation. This is perfectly valid code:
person = {
_id: "person123",
username: "lloyd-christmas"
}
comment = {
_id: "comment123",
person: "person123",
text: "This is how I start",
}
You don't have to do: person = {
_id: "person123",
username: "lloyd-christmas"
}
comment = {
_id: "comment456",
person: {
_id: "person123",
username: "lloyd-christmas"
},
text: "This is also valid"
};
Sure, a join is faster than the first one where you'll have to hit the DB twice. The point is that you don't have to START with denormalizing everything. I start with normalized data and do more DB reads than I need. I figure out how the application uses my data as I go along, and denormalize the pieces I need only once I need them and am confident I won't bump into consistency issues (my username isn't updating every 5 seconds). Through this process I realize what the actual relationships are in my application and how my app functions request to request. This allows me to better structure my data. This is a quick update in mongo and usually a couple of lines of refactoring in application logic.Obviously this is just an MCVE. My original point was that I find this to be a drastically more flexible process than starting off relational.