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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:45:06+00:00 2026-06-10T07:45:06+00:00

During the development of our map-reduce jobs our MR code generates useful diagnostic data

  • 0

During the development of our map-reduce jobs our MR code generates useful diagnostic data structures independently of the data being map-reduced. Is there an easy way to get these data out to the code that called mapReduce or to persist them in Mongo? Just writing to the log file is turning out to be very sub-optimal as (a) there is a lot of data there already and (b) our diagnostic info is highly structured and, in fact, we’d like to run queries against it.

My investigation so far suggests that MR data structures are passed by value (via serialization) so any in-memory data structures are lost, including those hooked to the “global” scope. The namespaces are isolated from the main JS server-side namespace so dbeval can’t seem to reach them (or, at least, I don’t know where to look). Last but not least, although all the database objects and functions are present, 10gen is generating (confusing) error messages to prevent their use, e.g., about coll.insert not being a function while typeof coll.insert === 'function' is true.

To be clear, I’m interested in doing this for development in a single node, because the logging/debugging support in MongoDB is pretty limited. This type of side-effects are not good in production environments.

  • 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-10T07:45:07+00:00Added an answer on June 10, 2026 at 7:45 am

    As surmised, it is not possible (as at MongoDB 2.2) to access another DB from within the Map/Reduce functions. Aside from potential performance impact, there is also the possibility of creating deadlocks and other unwanted side-effects.

    Unfortunately that leaves print() to the mongo log as the only “out of band” output option.

    Depending on your diagnostic output, one approach to try would be:

    • add a unique marker that would allow you to identify the output (or even the output run) in the log output

    • serialize your output using tojson() so it is logged with some parseable structure and ideally emitted on a single line when you print()

    • write a script to tail the mongod.log log for lines matching with your unique marker and insert those into another collection for reporting

    Example of code that will run from within a M/R function:

    var diag = {
        'run' : diagrun,
        'phase': 'map',
        'key'  : z
    }   
    print("MAPDIAG:" + tojson(diag));
    

    Example output:

    $ tail -f mongo.log | grep "^MAPDIAG"
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "dog" }
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "mouse" }
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "cat" }
    MAPDIAG:{ "run" : "20120824", "phase" : "map", "key" : "dog" }
    MAPDIAG:{ "run" : "20120824", "phase" : "reduce", "key" : "cat", "total" : 3 }
    MAPDIAG:{ "run" : "20120824", "phase" : "reduce", "key" : "dog", "total" : 2 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are working on a big project. During our development we faced with a
it's common to see something like this in code, hopefully only during development: //XXX:
During a development project, the delivered code can go between different stages different environment
HI, During the development of my app, I was using Thread.Sleep to give our
During development, our Android app is built using Eclipse (ADT). We use an eclipse
Our development database now has 263 tables. During development we only work with a
I am writing code to migrate data from our live Access database to a
In our environment, we have two in-house frameworks and a separate website. During development,
During our initial development we haven't worried about scaling concerns, just getting the bare
During development, I use this to load the latest jQuery: <script src=http://www.google.com/jsapi></script> <script type=text/javascript>

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.