Embedded vs referenced documents

Continuing the discussion from [Update #4] Building my first App - general advice for starters needed:

@captsaltyjack atomicity and transaction availability are properties of a dbms that comes in with a performance cost. If that’s what you need, then you should perhaps consider a more suitable database system for your app. mongodb shines in other areas.

But again, there are patterns available in mongodb as well, to get transactions. http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/ this is a generalized and successfully applied two-phased-commit approach that programmers have used long before there were the rdbms’ we know of today.

Meteor’s decision to diff on top level documents is not a database performance consideration by itself. It is a consideration of the DDP layer and works that way due to a number of other things as well.

Also, embedding documents and querying atomically for a complete set is not always desirable. Consider a tasks/notes scenario where a task may have anywhere between 0 to (theoratically) 1000000 notes! And consider needing to get only the latest 5 notes for each task in a stream and that you want to reactively update the query. It would be much more efficient to hit the db one extra time rather than load the whole doc set into memory and trim the data.

Anyway, this is a philosophical argument that does not have one clear winner. It depends on your use case and mdg had to make choices to provide a generalized approach that concerns much more than simply database or performance.

2 Likes