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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:19:56+00:00 2026-05-27T05:19:56+00:00

I am running mapreduce on a collection with 1.15M documents. In the case of

  • 0

I am running mapreduce on a collection with 1.15M documents. In the case of duplicates, when I return a result, I want to prefer some documents values over others (i.e. a field value in one document may be more accurate than another’s, but then again might not exist at all).

To choose a value, I define this function (arguments are in the order of most preferred to least preferred):

function getPreferredValue() {
var length = arguments.length;
for (var i = 0; i < length; i++) {
    if (arguments[i] != null) {
        return arguments[i];
    }
}
return null;
}

My mapreduce command looks like this:

db.runCommand({
mapreduce:"catalog",
query: {$or:[
    {name:/^HIP/i},
    {name:/^SAO/i}
]},
map:function() {
    emit({dummy:this.xref}, this); // give me the whole damn object then
},
reduce:function(key, values) {
    var tempObject = {hipObject: null, saoObject:null};
    for (var i = 0; i < values.length; i++) {
        if (values[i].name.search("/^HIP") != -1) {
            var hipObject = {bii: null, lii: null, class: null, radeg: null, decdeg: null, rapm:null, decpm:null, vmag:null, parallax:null, xref:null};
            hipObject.bii = values[i].bii;
            hipObject.lii = values[i].lii;
            hipObject.class = values[i].class;
            hipObject.radeg = values[i].radeg;
            hipObject.decdec = values[i].decdeg;
            hipObject.rapm = values[i].rapm;
            hipObject.decpm = values[i].decpm;
            hipObject.vmag = values[i].vmag;
            hipObject.parallax = values[i].parallax;
            hipObject.xref = values[i].xref;
            tempObject.hipObject = hipObject;
        }
        if (values[i].name.search("/^SAO") != -1) {
            var saoObject = {bii: null, lii: null, class: null, radeg: null, decdeg: null, rapm:null, decpm:null, vmag:null, parallax:null, xref:null};
            saoObject.bii = values[i].bii;
            saoObject.lii = values[i].lii;
            saoObject.class = values[i].class;
            saoObject.radeg = values[i].radeg;
            saoObject.decdec = values[i].decdeg;
            saoObject.rapm = values[i].rapm;
            saoObject.decpm = values[i].decpm;
            saoObject.vmag = values[i].vmag;
            saoObject.parallax = values[i].parallax;
            saoObject.xref = values[i].xref;
            tempObject.saoObject = saoObject;
        }
    }

    var result = {bii: null, lii: null, class: null, radeg: null, decdeg: null, rapm:null, decpm:null, vmag:null, parallax:null, xref:null}
    result.bii = getPreferredValue(tempObject.hipObject.bii, tempObject.saoObject.bii);
    result.lii = getPreferredValue(tempObject.hipObject.lii, tempObject.saoObject.lii);
    result.class = getPreferredValue(tempObject.hipObject.class, tempObject.saoObject.class);
    result.radeg = getPreferredValue(tempObject.hipObject.radeg, tempObject.saoObject.radeg);
    result.decdeg = getPreferredValue(tempObject.hipObject.decdeg, tempObject.saoObject.decdeg);
    result.rapm = getPreferredValue(tempObject.hipObject.rapm, tempObject.saoObject.rapm);
    result.decpm = getPreferredValue(tempObject.hipObject.decpm, tempObject.saoObject.decpm);
    result.vmag = getPreferredValue(tempObject.hipObject.vmag, tempObject.saoObject.vmag);
    result.parallax = getPreferredValue(tempObject.hipObject.parallax, tempObject.saoObject.parallax);
    result.xref = tempObject.hipObject.xref;

    return result;
},
out: {replace:"catalog2", db:"astro3"}
});

Unfortunately, when attempting to run, I get an error that getPreferredValue is not defined.

Probably a stupid error on my part, but can anyone assist?
Jason

  • 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-27T05:19:56+00:00Added an answer on May 27, 2026 at 5:19 am

    Disregard, I wasn’t saving the function server side.

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

Sidebar

Related Questions

In Mongo shell, after running a mapreduce on collection DEPS with output named STATS:
Running into a problem. I have a table defined to hold the values of
I want to execute a mapreduce query, in erlang, that contains two map phases
Running this in python will result in a WindowsError stating it cannot find the
I was running the MapReduce Matrix Multiplication program found at http://www.norstad.org/matrix-multiply/index.html . I found
I'm getting started with using python's mrjob to convert some of my long running
I have a large dataset (about 1.1M documents) that I need to run mapreduce
When running a MapReduce job with a specified combiner, is the combiner run during
I wrote some mapreduce jobs that reference a few external jars. so I added
I am running some map reduce jobs via the PHP client library as such:

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.