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:
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.
Comments
Yes... just... yes!
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!
Didn't you just describe a basic index side join? Nice
Theo, It is a bit more involved, since you also need to do updates on the fly when the referenced document changes, but yes.
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
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!
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!!!
How would one query this using the .Net Client API?
Shawn, In exactly the same manner. You have LoadDocument exposed to you in the AbstractIndexCreationTask
Can you give example code for querying this using the .NET Client API?
Jim, You just do, here is how you would do this using Lucene Query: session.Advanced.LuceneQuery<Courses>("CoursesAndStudents").WhereEquals("Students", "oren eini").ToList();
Brilliant, great feature and thanks for the quick response!
Comment preview