Ayende @ Rahien

It's a girl

RavenDB Feature of the Year: Indexing related documents

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:

image

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:

image

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:

image

And now we can query things like this:

image

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:

image

And then we can query it on:

image

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.

image

image

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.

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Matt  johnson
12/24/2012 05:47 PM by
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
12/24/2012 08:56 PM by
Theo Andersen

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

Ayende Rahien
12/24/2012 10:38 PM by
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
12/25/2012 12:12 AM by
Judah Gabriel Himango

Awesome new feature, Oren.

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

Mouhong
12/25/2012 03:01 AM by
Mouhong

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

Mike Scott
12/25/2012 02:44 PM by
Mike Scott

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

Galim
12/25/2012 09:53 PM by
Galim

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

Andrew
12/26/2012 12:59 AM by
Andrew

Brillant! Thanks for the Christmas present!

Erik Källén
01/07/2013 09:13 AM by
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
03/09/2013 04:49 AM by
Shawn de Wet

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

Ayende Rahien
03/10/2013 02:54 PM by
Ayende Rahien

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

Jim Paterson
03/13/2013 01:04 PM by
Jim Paterson

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

Ayende Rahien
03/13/2013 02:56 PM by
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
03/13/2013 09:39 PM by
Jim Paterson

Brilliant, great feature and thanks for the quick response!

Comments have been closed on this topic.