I am currently teaching a course in RavenDB, and as usual during a course, we keep doing a lot of work that pushes what we do with RavenDB. Usually because we try to come up with new scenarios on the fly and adapting to the questions from the students.
In this case, we were going over the map/reduce stack and we kept coming more and more complex example and how to handle them, and then we got to this scenario.
Given the following class structure:
Give me the count of all the species and all the breeds. That is pretty easy to do, right? In SQL, you would write it like this:
And that is nice, but it still means that you have to do some work on the client side to merge things up to get the final result, since we want something like this:
- Dogs: 6
- German Shepherd: 3
- Labrador: 1
- Mixed: 2
- Cats: 3
- Street: 2
- Long Haired: 1
In RavenDB, we can express the whole thing in a simple succinct index:
And the result of this beauty?
And that is quite pretty, even if I say so myself.