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 6036571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:56:39+00:00 2026-05-23T05:56:39+00:00

I am currently using MongoDB’s MapReduce to generate hourly ad view counts like this:

  • 0

I am currently using MongoDB’s MapReduce to generate hourly ad view counts like this:

{ _id : "4/1/2011 9:00 AM", value : { AdViews_Total : 4 } }

This works fine, and I get the results in a collection that I can subsequently query much more quickly than the original data. Now, what I’d like to do is something like this:

{ _id : "4/1/2011 9:00 AM", value : { ByBrowser : { "Internet Explorer" : 4, "FireFox" : 4 } } }

To do that, I think I’d need to be able to merge two or more disjoint documents in my Reduce operation, for example:

{ _id : "4/1/2011 9:00 AM", value : { ByBrowser : { "FireFox" : 3 } } }
{ _id : "4/1/2011 9:00 AM", value : { ByBrowser : { "FireFox" : 1 } } }
{ _id : "4/1/2011 9:00 AM", value : { ByBrowser : { "Internet Explorer" : 4 } } }

Does anyone know what such a Reduce operation might look like, keeping in mind that the browser names are not known ahead of time?

  • 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-23T05:56:40+00:00Added an answer on May 23, 2026 at 5:56 am

    I have managed to achieve what I am after using the following, though I suspect that there might be a more efficient way of doing it. I’ll leave this up for a day before marking as answer…

    function Reduce(key, arr_values) {
        var reduced = { 
            AdViews_Total : 0, 
            DefaultAdViews_Total : 0, 
            Sessions_Total : 0,
            Browsers : [ ],
            }; //a document
        for(var i in arr_values) {
            reduced.AdViews_Total += isNaN(arr_values[i].AdViews_Total) ? 0 : arr_values[i].AdViews_Total;
            reduced.DefaultAdViews_Total += isNaN(arr_values[i].DefaultAdViews_Total) ? 0 : arr_values[i].DefaultAdViews_Total;
            reduced.Sessions_Total += isNaN(arr_values[i].Sessions_Total) ? 0 : arr_values[i].Sessions_Total;
            if (null != arr_values[i].Browsers)
                for (var j in arr_values[i].Browsers)
                {
                    var browser = arr_values[i].Browsers[j]
                    var browserLabel = browser.Browser;
                    var browserCount = browser.Count;
                    var browserFound = false;
                    for (var k in reduced.Browsers)
                    {
                        if (reduced.Browsers[k].Browser == browserLabel)
                        {
                            reduced.Browsers[k].Count += browserCount;
                            browserFound = true;
                        }
                    }
                    if (!browserFound)
                        reduced.Browsers[0] = browser;
                }
        }
        return reduced;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using MongoDB to record application logs, and while I'm quite happy with
I'm designing an application that processes RSS feeds using MongoDB. Currently my collections are
I am developing a website using Codeigniter and MongoDB (Alex Bilbie library). Currently there
I'm currently using Casbah with MongoDB for implementing web service. I am having no
I am using MongoDB in our project and I'm currently learning how things work.
I'm currently using ASP.NET MVC3 and MongoDB for a web app. MongoDB uses UTC
I'm currently building a webserver in nodeJS that'll be using mongoDB. One of the
I am currently playing around with node.js and MongoDB using the node-mongo-native driver. I
I'm currently using mongoDB in my development server. Using PHP 1.1.4 driver and connecting
I am currently using MongoDB with millions of data records. I discovered one thing

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.