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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:53:32+00:00 2026-05-25T09:53:32+00:00

I have a map reduce like this: map: function() { emit(this.username, {sent:this.sent, received:this.received}); }

  • 0

I have a map reduce like this:

map:

function() {
        emit(this.username, {sent:this.sent, received:this.received});
}

reduce:

function(key, values) {                                                                                                                                                                                                         
    var result = {sent: 0, received: 0, entries:0};

    values.forEach(function (value) {
        result.sent += value.sent;
        result.received += value.received;
        result.entries += 1;
    });

    return result;
}

I’ve been monitoring the amount of entries processed in the result map, as you can see. I’ve found I get much lower numbers of accessed records than I should.

For my particular data set, the output is like so:

[{u’_id’: u’1743′, u’value’: {u’received’: 1406545.0, u’sent’: 26251138.0, u’entries’: 316.0}}]

As I’m running the map reduce with a query option, specifying a username and a date range.

If I perform the same query using db.collection.find() as follows, the count is different:

> db.entire_database.find({username: '1743', time : { $lte: ISODate('2011-08-12 12:40:00'), $gte: ISODate('2011-08-12 08:40:00') }}).count()                        
1915

The full map reduce query is this:

db.entire_database.mapReduce(m, r, {out: 'myoutput', query: { username: '1743', time : { $lte: ISODate('2011-08-12 12:40:00'), $gte: ISODate('2011-08-12 08:40:00') } }  })

So basically, I’m unsure why the count is so radically different? Why is the find() giving me 1915, but the map reduce is 316?

  • 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-25T09:53:33+00:00Added an answer on May 25, 2026 at 9:53 am

    Your map function needs to emit an object with the same form as the reduce function (ie. it should have an entries field set to 1). You can read more about this here.

    Basically, the values that are passed to the reduce function are not necessarily the raw outputs emitted from map. Rather than being called once, the reduce function is called many times on ‘groups’ of values produced by map, the results of which are then combined again by being passed into a further call of the reduce function. This is what makes MapReduce horizontally scalable, because any group of emitted values can be farmed out to any server in any order before being combined later.

    So I would restructure your functions slightly like this:

    map:

    function() {
        emit(this.username, {sent:this.sent, received:this.received, entries : 1});
    }
    

    reduce:

    function(key, values) {                                                                                                                                                                                                         
        var result = {sent: 0, received: 0, entries:0};
    
        values.forEach(function (value) {
            result.sent += value.sent;
            result.received += value.received;
            result.entries += value.entries;
        });
    
        return result;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I'm just learning mapReduce. I have the following map reduce function being called on
I have unsorted map of key value pairs. input = { xa => xavalue,
I have a map of a building and I'd like to programmatically highlight specific
I have to map a REST Webservice URL like http://server:8080/application/service/customer/v1 to createCustomer method in
I have a collection where each document looks like this {access_key:'xxxxxxxxx', keyword: banana, count:12,
I have a SQL database with two tables like this: Users Id (PK) Name
I have documents like this in my CouchDB: { _id: 0cb35be3cc73d6859c303fa3200011d2, _rev: 1-f6e356bbf6ab09290aae11132af50d66, adresse:
Just learning Map/Reduce and I'm missing a step. I've read this post ( RavenDB
I have a Class something like this in java for hadoop MapReduce public Class

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.