Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:40:15+00:00 2026-05-30T22:40:15+00:00

I have a City document, Site document. City can have multiple sites. Site document

  • 0

I have a City document, Site document. City can have multiple sites. Site document has the city information in it. There are about 100 city documents and 10000 site documents in RavenDB

City Document:

{
    "CityCode": "NY",

    "CityName": "New York"
}

Site Document:

{
    "SiteName": "MOMA",

    "CityCode": "NY"
}

Objective is to get a list of all cities and the number of sites for each like…

City   Sites
NY     12
CH      33
BO      56
and so on....

I am doing this.

int countSites = session.Query<Site>()
                        .Count();


var SiteCityList = session.Query<Site>()
                          .Take(countSites)
                          .ToList()
                          .GroupBy(x => x.CityCode)
                          .OrderBy(x => x.Count())
                          .ToDictionary(x => x.Key, x => x.Count());

This does not give all the data in the ravendb. I get only 11 rows of count by site at any time and even the counts are not accurate. What I want is to get a list of all 100 cities and number of sites for each city (in 100s) as a list as shown above. Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:40:16+00:00Added an answer on May 30, 2026 at 10:40 pm

    Use a map/reduce index like this

    public class CityCodeCount : AbstractIndexCreationTask<Site, CityCodeCount.ReduceResult>
    {
        public class ReduceResult
        {
            public string CityCode { get; set; }
            public int Count { get; set; }
        }
    
        public CityCodeCount()
        {
            Map = sites => from site in sites
                            select new
                            {
                                site.CityCode,
                                Count = 1
                            };
    
            Reduce = results => from result in results
                                group result by result.CityCode
                                into g
                                select new
                                {
                                    CityCode = g.Key,
                                    Count = g.Sum(x => x.Count)
                                };
    
        }
    }
    

    Later then, you can query it easily.

    var results = documentSession.Query<CityCodeCount.ReduceResult, CityCodeCount>()
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small class called City that simply holds some information about a
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
I have a table as shown below Q_ID DeptID EmployeeName City 100 100 testest
I have a simple XML document containing two city id's. <?xml version=1.0 encoding=ISO-8859-1?> <config>
I have a CodeIgniter MVC application. I have a model called city that has
I have a script as below document.getElementById('lan').innerHTML=lan; document.getElementById('city').innerHTML=city; document.getElementById('text1').value=city+'|'+lan; The variables lan and city
I have city database with country,state,city,postalcode,areacode. The city is not distinct ..for eg one
I have a city map of Moscow. We modified a Google Maps image with
I'm currently setting up CI for my project and have team city configure and
I have this code: dojo.declare(City, null, { constructor : function(cityid, cityinfo){ } }); dojo.declare(TPolyline,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.