Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need a map-reduce index to do this. Here's a short console program that demonstrates:</p> <pre><code>using System; using System.Linq; using Raven.Client.Document; using Raven.Client.Indexes; namespace ConsoleApplication1 { public class Customer { public string Id { get; set; } public string Name { get; set; } public string City { get; set; } } public class Customers_ByCity : AbstractIndexCreationTask&lt;Customer, Customers_ByCity.Result&gt; { public Customers_ByCity() { Map = customers =&gt; from customer in customers select new { customer.City, Count = 1 }; Reduce = results =&gt; from result in results group result by result.City into g select new { City = g.Key, Count = g.Sum(x =&gt; x.Count) }; } public class Result { public string City { get; set; } public int Count { get; set; } } } class Program { private static void Main() { var documentStore = new DocumentStore { Url = "http://localhost:8080" }; documentStore.Initialize(); IndexCreation.CreateIndexes(typeof(Program).Assembly, documentStore); using (var session = documentStore.OpenSession()) { session.Store(new Customer { Name = "John", City = "NY" }); session.Store(new Customer { Name = "Jane", City = "NY" }); session.Store(new Customer { Name = "Jim", City = "NY" }); session.Store(new Customer { Name = "Sally", City = "LA" }); session.Store(new Customer { Name = "Sam", City = "LA" }); session.Store(new Customer { Name = "Suzie", City = "LA" }); session.Store(new Customer { Name = "Sarah", City = "LA" }); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { // In a real app, you probably don't want to wait for nonstale results. // You will also want to consider what to do if you have more than one page of results (more than 1024 cities) var counts = session.Query&lt;Customers_ByCity.Result, Customers_ByCity&gt;() .Customize(x=&gt; x.WaitForNonStaleResults()) .Take(1024); foreach (var result in counts) { Console.WriteLine("{0}: {1}", result.City, result.Count); } Console.WriteLine(); } Console.ReadLine(); } } } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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