Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

RavenDB Feature of the Year: Indexing related documents

time to read 3 min | 593 words

I am pretty sure that this feature is going to be at the very top of the chart when people talk about 2.0 features that they love. This is a feature that we didn’t plan for in 2.0. But we got held up by the memory issues, and I really needed to do something awesome rather than trolling through GBs of dump files. So I decided to give myself a little gift and do a big cool feature as a reward.

Let us imagine the following scenario:


We want to search for invoices based on the customer name. That one is easily enough to do, because you can use the approach outlined here. First do a search on the customer name, then do a search based on the customer id. In most cases, this actually result in better UX, because you have the chance to do more stuff to find the right customer.

That said, a common requirement that also pops up is the need to sort based on the customer name. And that is were things gets complex. You need to do things like multi map reduce, and it get hairy (or get bald, depending if you tear at your hair often or not).

Let us look at another example:


I want to looks for courses that have students named Oren.  There are solutions for that, but they aren’t nice.

Here is where we have the awesome feature, indexing related documents:


And now we can query things like this:


And obviously, we can do all the rest, such as sort by it, do full text searching, etc.

What about the more complex example? Students & Courses? This is just as easy:


And then we can query it on:


But wait! Yes, I know what you are thinking. What about updates? RavenDB will take care of all of that for you behind the scenes. When the referenced document change, the value will be reindexed automatically, meaning that you will get the updated value easily.



This feature is going to deal with a lot of pain points that people are currently getting, and I am so excited I can barely sit.


Matt  johnson

Amazing work! This is going to really come in handy.

What I really love is now when people say "you can't do joins in nosql" - I can smile and say "oh yes you can!" - well, not exactly a true join in the Cartesian product sense, but certainly the same intent and benefit. Ayende - you rock!

Theo Andersen

Didn't you just describe a basic index side join? Nice

Ayende Rahien

Theo, It is a bit more involved, since you also need to do updates on the fly when the referenced document changes, but yes.

Judah Gabriel Himango

Awesome new feature, Oren.

Can't wait until 2.0 is done and up on NuGet.


Cool! I was just looking for such a feature some days ago

Mike Scott

Killer feature, Oren! And first time I read "I am so excited I can barely sit" I misread "sit", haha!


This is exactly the feature that we needed a lot! Thanks Ayende! Awesome Christmas gift for developers who love RavenDB :)


Brillant! Thanks for the Christmas present!

Erik Källén

My biggest pain with NoSQL is that they never contain any simple, efficient way of performing a join (denormalization is sometimes desired, sometimes not depending on your use-case). This pain has now gone away! Awesome feature!!!

Shawn de Wet

How would one query this using the .Net Client API?

Ayende Rahien

Shawn, In exactly the same manner. You have LoadDocument exposed to you in the AbstractIndexCreationTask

Jim Paterson

Can you give example code for querying this using the .NET Client API?

Ayende Rahien

Jim, You just do, here is how you would do this using Lucene Query: session.Advanced.LuceneQuery("CoursesAndStudents").WhereEquals("Students", "oren eini").ToList();

Jim Paterson

Brilliant, great feature and thanks for the quick response!

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats