One of the main differences between relational databases and document databases is the lack of native joining capabilities, right? This is no longer true for RavenDB. Yes, we already had very effective ways to deal with document relations before, but now in RavenDB 2.0 we can do much better.
Let’s say our model looks like this:
In order to display a list of posts, we need the title, the author’s name and the content. So we effectively need to join posts with their authors. This is what we want:
If you don’t know how to do this in RavenDB 1.0, please go to this post.
In RavenDB 2.0 however, there is a new feature that let’s us load documents during indexing time. This means, we can load the related author document while we index the post document. Combine this features with the possibility to use an index as the read-store for your queries…
Here’s how our index looks like:
Note how we first load the author document and then store the author’s name inside our index, so we can get that value back at query time.
Here’s how a query looks like:
How awesome is that?
Please note that RavenDB does not load the author document at query time. Instead, it already has the author’s name stored in the index, so querying is as ultra-fast as if there wasn’t any relation at all.
If the author’s name changes, RavenDB will automatically recompute the index for all the posts that are related with that author. Unlike with denormalized references, we don’t need to maintain that relation!
Personally, I think this will fundamentally change how we work with RavenDB. Do you agree?