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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:09:06+00:00 2026-05-27T14:09:06+00:00

When using map/reduce on MongoDb 2.0.1, it seems that the finalize method is not

  • 0

When using map/reduce on MongoDb 2.0.1, it seems that the finalize method is not always called with the same arguments.

I am doing a regular counting + average at the end.

var m = function() {
    emit(this.testName, {
        worked: Number(this.testStatus == "WORKED"),
        failed: Number(this.testStatus == "FAILED"),
        done: Number(this.testStatus == "DONE"),
        count: 1
    });
}

var r = function(key, values) {
    var result = {
        worked: 0,
        failed: 0,
        done: 0,
        count: 0
    }

    values.forEach(function(value) {
      result.worked += value.worked;
      result.failed += value.failed;
      result.done += value.done;
      result.count += value.count;
    });

    return result;
}

var f = function(key, value) {
    data = value || key;
    data.workedMean = data.worked / data.count;
    return data;
}

var cmd = {
    mapreduce: "tests",
    map: m,
    reduce: r,
    finalize: f,
    out: {
        reduce: "fromMongo"
    },
    jsMode: true
}

When the fromMongo collection is empty, f() is called with only one argument, the value. When fromMongo already has values (notice that I use reduce as my out map/reduce parameter), the f() method get two arguments: key and value.

Is that a known behavior?
I managed two make it work using data = value || key;, but I don’t think this is the solution.

  • 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-27T14:09:07+00:00Added an answer on May 27, 2026 at 2:09 pm

    this problem is due to a difference in finalize call between the jsMode and non-jsMode (which happens during the post processing of “reduce” mode).
    The workaround is to not use jsMode:true, in which case it should always be called with (key, value).

    Created a server issue:
    https://jira.mongodb.org/browse/SERVER-4535

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

Sidebar

Related Questions

I know about map/reduce alghoritm and its use. It's using functions that are called
Is it true that Map/Reduce results can be stored permanently, but not sorted? For
This is my first time using map/reduce. I want to write a program that
I'm gluing together a number of system calls using the Amazon Elastic Map Reduce
What happens when the datanode the map/reduce is using goes down? Shouldnt the job
Is it doable to create an Apriori app using map-reduce? I am starting out
I have tried a simple Map/Reduce task using Amazon Elastic MapReduce and it took
Is there a distance calculation implementation using hadoop map/reduce. I am trying to calculate
Is there a simple Map-Reduce library or implementation for .NET that allows a task
I am using map kit and showing customized annotation view. One is carImage and

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.