2

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)?

Shawn de Wet
  • 5,642
  • 6
  • 57
  • 88
  • See my comments in your [other question](http://stackoverflow.com/a/15210218/634824). I'd like to refer you to [the RavenDB Google Group](https://groups.google.com/forum/?fromgroups#!forum/ravendb) if you have additional questions regarding understanding modeling. Let's keep Stack Overflow for specific code. Thanks. – Matt Johnson-Pint Mar 05 '13 at 14:04
  • 2
    imho this question is a great fit for SO – jgauffin Mar 05 '13 at 14:08

1 Answers1

2

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).

Community
  • 1
  • 1
jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • So just to be clear, the answer is, if you store a document with a nested collection, each time you load the document, the entire nested collection gets loaded with it? – Shawn de Wet Mar 06 '13 at 02:18
  • Yes, unless you've created an index and query explicitly through the index. The collection is part of the document, so it's only natural that it gets loaded. – jgauffin Mar 06 '13 at 05:36