We will create a new index which will aggregate the World
database to make a count of Cities
that have the same name in different countries and return the CountryId
key for each city as a single document. The following screenshot illustrates the expected result:
Start Visual Studio and open the
RavenDB_CH05
solution.Add a new class to the project, name it
Cities_SameName
and add the following code snippet:Tip
We named the embedded class
ReduceResult
by convention. You can choose any other name for this class and place it outside the index class.We could use a
String
type in theReduceResult
class to store the document IDCountriesId
(which is astring
type), but we choose to create a second embedded class, for learning purposes and show that it is possible to create more complex structure.Add a default constructor to the
Cities_SameName
class and within this constructor add the indexMap
function using the following code snippet...