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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:11:36+00:00 2026-06-06T00:11:36+00:00

I broken my mind understanding mapreduce. So, I ask you for help. I have

  • 0

I broken my mind understanding mapreduce.
So, I ask you for help.

I have such entity:

public class ConstraintSpec
{
    [BsonId]
    public int Id { get; set; }
    public bool OrderRequired { get; set; }
    public ActionTypeConstraintSpec[] ActionTypeConstraintSpecs { get; set; }
}

And I’am trying to write my id generator.

Here is my “don’t working” MapReduce js code:

Map = "map = function () {" +
              "emit(this._id)}";

        Reduce = "reduce = function (key, values) {" +
                     "var max = this[0];" +
                     "var len = this.length;" +
                     "for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];" +
                     "return max;" +
                 "}";

Then I writing:

var mapreduce = cont.MapReduce(Map, Reduce);
        var x = mapreduce.GetResults();

But nothing works.

Please, help!

  • 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-06T00:11:37+00:00Added an answer on June 6, 2026 at 12:11 am

    What are you trying to accomplish with map reduce, and for which field do you need to find the maximum? In your map function you need to emit the values that you are trying to aggregate/compare; you’re currently only emitting a key, this.id. Presumably the _id is unique for each document, which will prevent the reduce function from being called (reduce is not called if a single document was emitted for a particular key). The key needs to be the name of the field over which to aggregate the data.

    For example, in the shell:

    input data:

    {_id: 1, name: "test1", number: 5}
    {_id: 2, name: "test1", number: 8}
    {_id: 3, name: "test2", number: 3}
    {_id: 4, name: "test2", number: 11}
    

    Map function:

    function () {
        emit{this.name, this.number}
    }
    

    Reduce function:

        function(key, values) {
            var max = 0;
            values.forEach(function(value) {
               if(value > max){
                  max = value;
               }
            });
            return max;
        }
    

    output data:

    {_id: "test1", value: 8}
    {_id: "test2", value: 11}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have broken validates_confirmation_of in my rails app. My model looks like
I have my site broken down into several folders by language: / /en/ index.php
I have some older (broken) code that has a join using a *= table1.ID
I have a map of the UK broken down into various geographic regions. I
I currently have a broken site structure that needs repair and I want to
I have broken some code in my last 4-5 revisions / pushes to main
We have broken Google's APK size limit and are planning to send our download
I have about 8 text inputs. They all get concatenated with PHP in the
We have an application wrote in C#, which broken into several projects. These projects
broken to bare-bones scene: I have a program in c# that calls a .exe

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.