Question

I have an object like "Library":

public class Library
{
    List Books {get; set}
}

Book
{
    string isbn
}

I want to make an index so from a given isbn I can find the library I can't figure out how to make the map reduce.

Was it helpful?

Solution

No reduce would be necessary to index by isbn. Think of reduce when you need aggregates (sum, count, average, min, max, etc.)

In fact, you don't even need to write the index yourself. Just let Raven do the work for you with it's dynamic index features.

var librariesContainingTheBook = session.Query<Library>()
                                 .Where(x=> x.Books.Any(y=> y.isbn == yourIsbn))

RavenDB should be able to parse this query and build the index automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top