Reputation: 5976
In the scenario of Question and Comments...where comments don't exist on their own, but are stored as nested elements within their parent question document...these comments could of course build up to hundreds and hundreds of entries...won't I incur a performance penalty when I load up a Question? Won't that load operation also load up all hundreds and hundreds of comments? What query could (should) I run in order to load up the question, but then only load up the first 10 comments, to have the ability to load up another "page" of comments as I need to?
Or does RavenDB apply lazy loading, in that it does not load up the Comments at all until I access the Comments property of the Question instance? And even so...could I control that it "lazy" loads the comments in a paged fashion?
Also, how would I add a new comment to a Question without first having to Load the question (with all its comments)?
Upvotes: 2
Views: 271
Reputation: 101130
When you load a document you typically want to load everything (i.e. the details page in blog).
For the index page (listing all blog posts) you can create an index which do map/reduce.
As for saving a new comment you might want to ask yourself how often you do that? In most web sites reads are much more frequently used than writes. So the performance penalty for loading the entire blog is not so relevant when looking at the whole picture.
But if you do expect to have A LOT of comments, you might want to redesign your application later on to make comments root aggregates. But don't do that until it's proven to be a performance issue. (It's also easy to move the comments thanks to the schemaless nature of RavenDB).
Upvotes: 2