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

  • Home
  • SEARCH
  • 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 9100375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:50:55+00:00 2026-06-17T00:50:55+00:00

Suppose I have web application errors reported to mongo db. To fetch them (grouped

  • 0

Suppose I have web application errors reported to mongo db. To fetch them (grouped by URLs) I use the following query:

db.errors.group({
    cond: {
        date:{
            $gt:new Date(2013,0,3, 6, 0, 0), 
            $lt:new Date(2013,0,3, 8, 0, 0)
        }
    },
    key: {
        url: 1
    },
    initial: {
        csum: 0
    },
    reduce:
        function(obj, prev) {
            prev.csum++;
        }
})

What should I do if I would like to count the errors by a site url (as opposed to a page url)? I mean, that http://www.mysite.com/page1 and http://www.mysite.com/page2 will be counted in the same bucket. Ideally, it would be a function in the key section of the query somehow…

  • 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-06-17T00:50:57+00:00Added an answer on June 17, 2026 at 12:50 am

    To extend JohnnyHK’s answer:

    db.errors.group({
        cond: {
            date:{
                $gt:new Date(2013,0,3, 6, 0, 0),
                $lt:new Date(2013,0,3, 8, 0, 0)
            }
        },
        keyf: function(doc)
        {
            return { site: doc.url.match(/.*:\/\/[^\/]+/i)[0]};
        },
        initial: {
            csum: 0
        },
        reduce:
            function(obj, prev) {
                prev.csum++;
            }
    })
    

    Returns:

    [
        {
            "site" : "http://www.mysite.com",
            "csum" : 3
        },
        {
            "site" : "http://www.example.com",
            "csum" : 1
        }
    ]
    

    With a large dataset it’s not going to be fast though. If you control the code that generates the errors it might be easier to add a domain field you could group on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose I have a web application made with Backbone, which use Backbone.Router for
Suppose I have a web application, which uses jQuery for Ajax and UI. Now
Suppose that you have a big Data Entry Web Application Like Microsoft CRM ,
I have an ASP.NET Web Forms application in VB.NET In my application I use
I have the following code that supposed to send data from web application developed
I'm working on a web application. I have entities that are supposed to be
The setup is suppose I have 2 memcached servers, and 2 web servers to
Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a
I am using Spring MVC to build my web application, and I have a
I have an ASP.NET Web Application project that used to target ASP.NET 2.0. I

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.