Note that there are some explanatory texts on larger screens.

plurals
  1. PORavenDB MultiMap Index
    primarykey
    data
    text
    <p>I am new to RavenDB. I am trying to use a multi map index feature, though I am not sure if it is the best approach to my problem. So I have three documents: Unit, Car, People.</p> <p>Car document looks like this:</p> <pre><code>{ Id: "cars/123", PersonId: "people/1235", UnitId: "units/4321", Make: "Toyota", Model: "Prius" } </code></pre> <p>People document looks like this:</p> <pre><code>{ Id: "people/1235", FirstName: "test", LastName: "test" } </code></pre> <p>And unit doc:</p> <pre><code>{ Id: "units/4321", Address: "blah blah" } </code></pre> <p>This is an abbreviated example, in my real app there are way more fields, so data de-normalization would be my last resort.</p> <p>I need to create and index that will have all of this three docuemnts joined in one document. Something like this:</p> <pre><code>{ CarId: "cars/123", PersonId: "people/1235", UnitId: "units/4321", Make: "Toyota", Model: "Prius" FirstName: "test", LastName: "test" Address: "blah blah" } // same unit different person owns a different car { CarId: "cars/122", PersonId: "people/1236", UnitId: "units/4321", Make: "Toyota", Model: "4runner" FirstName: "test", LastName: "test" Address: "blah blah" } </code></pre> <p>In a relational database I would just use two joins to People and Unit tables by ids and my car table would be an aggregate entity.</p> <p>Here is the index definition that I have:</p> <pre><code> public class MyMultiIndex : AbstractMultiMapIndexCreationTask&lt;JoinedDocument&gt; { public MyMultiIndex() { // creating maps AddMap&lt;Car&gt;(cars =&gt; cars.Select(e =&gt; new { e.CarId, e.Make, e.Model, PersonId = e.PersonId, UnitId = e.UnitId, FirstName = (null)string, LastName = (null)string, Address = (nul)string })); AddMap&lt;People&gt;(people =&gt; people.Select(e =&gt; new { CarId = (string)null, Make = (string)null, Model = (string)null, PersonId = e.Id, UnitId = (null)string, FirstName = e.FirstName, LastName = e.LastName, Address = (nul)string })); AddMap&lt;Unit&gt;(people =&gt; people.Select(e =&gt; new { CarId = (string)null, Make = (string)null, Model = (string)null, PersonId = (null)string, UnitId = e.null, FirstName = (nul)string , LastName = (nul)string , Address = e.Address })); Reduce = results =&gt; from result in results group result by result.CarId into g select new JoinedDocument { CarId = g.Key, PersonId = g.First(e =&gt; e.CarId == g.Key).PersonId, UnitId = g.First(e =&gt; e.CarId == g.Key).UnitId, Model = g.First(e =&gt; e.CarId == g.Key).Model, Make = g.First(e =&gt; e.CarId == g.Key).Make, **// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for people document did not work.** FirstName = results.First(e =&gt; e.PersonId == g.First(ie =&gt; ie.CarId == g.Key).PersonId).FirstName, **// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for people document did not work.** LastName = results.First(e =&gt; e.PersonId == g.First(ie =&gt; ie.CarId == g.Key).PersonId).LastName, **// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for unit document did not work.** UnitAddress = results.First(e =&gt; e.UnitId == g.First(ie =&gt; ie.CarId == g.Key).UnitId).LastName, }; Index(map =&gt; map.Model, FieldIndexing.Analyzed); Index(map =&gt; map.Make, FieldIndexing.Analyzed); Index(map =&gt; map.LastName, FieldIndexing.Analyzed); Index(map =&gt; map.FirstName, FieldIndexing.Analyzed); Index(map =&gt; map.Make, FieldIndexing.Analyzed); Index(map =&gt; map.UnitAddress, FieldIndexing.Analyzed); } } </code></pre> <p>When RavenDb runs this index I see errors when it is trying to run the Reduce function I have provided. It throws error when I am trying to match a record where person's first name and last name exist, same happens with the unit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload