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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:06:27+00:00 2026-06-12T04:06:27+00:00

How do I access the output from the following mongoDB map reduce code? I

  • 0

How do I access the output from the following mongoDB map reduce code? I assume that the map reduce function is producing a collection called ‘session_stat’ with fields: ‘dayOfWeek’ and ‘count’ that I can print using find() and my printValue function. But when I execute the code using ‘mongo code.js’, I just get “undefined”. Thanks in advance.

db = db.getSiblingDB("mrex");

// simulate saving records that log the lengths of user sessions in seconds                                                                                                                                                                                                                                                                                                 
db.session.save({userid:"a", time: ISODate('2011-11-03 14:17:00'), length: 95});
db.session.save({userid:"b", time: ISODate('2011-11-03 14:23:00'), length: 110});
db.session.save({userid:"c", time: ISODate('2011-11-03 15:02:00'), length: 120});
db.session.save({userid:"d", time: ISODate('2011-11-03 16:45:00'), length: 45});

function mapf()
{
    emit(this.time.getDay(),
     {count:1});
}

function reducef(key, values)
{
    var r = {dayOfWeek:key, count:0};
    values.forEach(function(v)
               {
                   r.count += v.count;
               });
    return r;
}

var mrcom1 = db.runCommand( { mapreduce:"session",
                          map:mapf,
                          reduce:reducef,
                          query: {time: {$gt:ISODate('2011-11-03 00:00:00')}},
                          out: { reduce: "session_stat" }
});

function printValue (r) {
    print(r.count)
};

db.session_stat.find().forEach(printValue)
  • 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-12T04:06:28+00:00Added an answer on June 12, 2026 at 4:06 am

    MongoDB’s map-reduce command generates a set of documents with a field named “value”, which contains the reduce return value. You’ll need to reach inside this field to find your subdocument.

    Use this instead as your printValue function:

    function printValue (r) {
        print(r.value.count)
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access the output from the listFields geoprocessing object using the following
I need to create an ANSI text file from an Access recordset that outputs
I'm using the following code to get the user details from Twitter in iOS
Hey fellas, I have the following VBA code. It gets the values from an
I want to generate some formatted output of data retrieved from an MS-Access database
The output of the following code on a random page is : print $_SESSION['uid'];
I'm getting the following (str) back from Disqus, JSON expected: ?({code: 0, response: {username:
Just out of curiosity, how does iostream access the input-output system. (I have a
I'm trying to access the http://s3.amazonaws.com/commoncrawl/parse-output/segment/ bucket with boto. I can't figure out how
I changed the tree of my JSON-P output, and i cannot access to my

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.