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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:44:48+00:00 2026-05-31T00:44:48+00:00

I am using Perl v5.12 with the MongoDB package v0.45. I would like to

  • 0

I am using Perl v5.12 with the MongoDB package v0.45.

I would like to run a MapReduce job to create a new collection that I will then create a cursor for later.
My other desire is that this job runs on a replica and not on the master.

As defined in the perl doc, MapReduce jobs are to be executed using the run_command method.
When I execute the perl script, I get:

Mongo error: not master at perlib/Connections.pm line 63.

After reading the MongoDB documentation on CPAN, there seems only to be a method for enabling cursors to read from replicas. So that method doesn’t apply to calls to run_command().

Here’s my code:

sub get_data {
    my $self = shift;
    my $dbh = shift;
    my $collection_h = shift;   
    my $since_time = $self->get_date_time(shift);
    my $loop_limit = $self->get_data_limit(shift);

    my %data = ();
    my $ctr = 0;

    my $temp_collection='temp_collection';

    my $ids = $dbh->run_command([
         "mapreduce" => $collection_h->{'name'}
        ,"map" => _get_map()
        ,"reduce" => _get_reduce()
        ,"query"    =>  {'to.id' => {'$exists'=>'true'}, 'updatedDate' => { '$gte' => $since_time }}
        ,"out" => $temp_collection      
    ]);

    die ("Mongo error: $ids") unless ref($ids) eq 'HASH';

        # next we create a cursor to this new collection
    my $cfs_h = $dbh->$temp_collection;
    my $id_cursor = $cfs_h->find()->limit($loop_limit);

    $id_cursor->slave_okay(1);
    $id_cursor->immortal(1);
    ...
}

sub _get_map {
    return "function() {emit(this.to.id, 1);}"; 
}

sub _get_reduce {

    return "function(k,vals) {return 1;}"
}

Has anyone encountered this problem of trying to use MapReduce on a replica?
Have you done it successfully?
If so, could you please share how you did it.

  • 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-31T00:44:50+00:00Added an answer on May 31, 2026 at 12:44 am

    When performing a Map/Reduce operation on a secondary, the results must be returned inline. The output must be returned with the “results” object and cannot be written to disk, because secondaries cannot be written to. When the results are output in this fashion, there is a limit of 16MB for the results set. There is a note on this under the “{ inline : 1}” bullet in the “Output options” section of the Map Reduce documentation. http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Outputoptions

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

Sidebar

Related Questions

I'm using Perl to run through a tree, and then calculate the leaf nodes
I'm using Perl's XML::Simple to parse deeply nested XML and would like to extract
I'm using Perl. I have the tag, for example: XYZ_PKM_HTML I would like to
I'm using Perl's DBI module. I prepare a statement using placeholders, then execute the
I am using Perl Regular expressions. How would i go about ignoring white space
I've just started working with mongodb got a perl script that parses a twitter
Using Perl's XML::LibXSLT necessitates that I use XSLT 1.0, which means that I am
I'm using Perl, and I want to create variables in loop. So each loop
Using Perl, without using any extra modules that don't come with ActivePerl, how can
I'm using perl to assemble a multipart-MIME email, which I'm then sending using sendmail,

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.