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,125 | Comments: 45,486

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.


  1. The design of RavenDB 4.0: Physically segregating collections - one day from now
  2. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - about one day from now
  3. RavenDB 3.5 whirl wind tour: I'll have the 3+1 goodies to go, please - 5 days from now
  4. The design of RavenDB 4.0: Voron has a one track mind - 6 days from now
  5. RavenDB 3.5 whirl wind tour: Digging deep into the internals - 7 days from now

And 12 more posts are pending...

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    03 May 2016 - Making Lucene reliable
  2. RavenDB 3.5 whirl wind tour (14):
    04 May 2016 - I’ll find who is taking my I/O bandwidth and they SHALL pay
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats