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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:59:24+00:00 2026-06-14T22:59:24+00:00

After playing with mapreduce with mongoDB, I worry about the results having two dimensions

  • 0

After playing with mapreduce with mongoDB, I worry about the results having “two dimensions” instead of flat documents.

I.e. the documents look like {id:…, value:{test:123}}

Instead, I’d prefer this format: {…,test:123}

How to chose this style for the results/output collection?

Thanks

  • 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-14T22:59:25+00:00Added an answer on June 14, 2026 at 10:59 pm

    The output collection from a MongoDB map/reduce job will always have a top-level structure of

    {_id: <something>, value: <something> }
    

    That is, it will always be a document with two keys. If you want to have the ‘value’ be a single value, you can do so by controlling your emit() and reduce() functions.

    Here is an emit() function that will emit a single value for ‘value’:

    emit() { this.date, 1 }
    

    Here is a reduce() function that will return a single value for ‘value’:

    reduce() {
      var count = 0;
    
      values.forEach(function(v) {
        count += v;
      });
    
      return count;
    };
    

    Remember: the “shape” of the document emitted by emit() MUST be the same as the one returned by reduce().

    If you do this, the documents in the output collection will look something like this:

    { _id: ISODate("2012-11-27T00:27:41.103Z"), value: 99 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've used DbUnit but after playing about with the Play Framework recently I've found
I've just started with Three.js. Like really just now. After playing with it for
After playing with Node.js and reading about async i/o & evented programming a lot
After seeing this question about replicating SQL select-statement-like behavior in Pandas, I added this
After playing around with Vaadin for about a week I'm curious about how Vaadin
Yeah I've drawn a blank on the this one, and after playing about with
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
After playing quite a bit of Bad Company 2 over the last month, I'm
Update: After playing around with this for a few hours, went with a multi-query
I am in the process of creating a synthesiser for iOS. After playing around

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.