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 a city table that has two columns from_city to_city now lets assume
So I have a city model. Each city has a Name attribute as well
I have a table of data that has a state and city column. I
I have a simple XML document containing two city id's. <?xml version=1.0 encoding=ISO-8859-1?> <config>
I have objects with 3 string fields Country, Province, City. They can contain null
I have a document called login_info . It has two fields: name password Location
I have a CodeIgniter MVC application. I have a model called city that has
As you may know, you can have suggestions from Google places API for city
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 a select that looks like this: <select id=select-site title=????> <optgroup label=City> <option

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.