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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:47:32+00:00 2026-05-22T23:47:32+00:00

This is a code example from this tutorial: http://kylebanker.com/blog/2009/12/mongodb-map-reduce-basics/ He notes that as of

  • 0

This is a code example from this tutorial:

http://kylebanker.com/blog/2009/12/mongodb-map-reduce-basics/

He notes that “as of MongoDB v1.8, you must specify an output collection name.” But I don’t see where this is referred to or why it is needed.

# Running map-reduce from Ruby (irb) assuming
# that @comments references the comments collection

# Specify the map and reduce functions in JavaScript, as strings
>> map    = "function() { emit(this.author, {votes: this.votes}); }"
>> reduce = "function(key, values) { " +
  "var sum = 0; " +
  "values.forEach(function(doc) { " +
  " sum += doc.votes; " +
  "}); " +
  "return {votes: sum}; " +
"};"

# Pass those to the map_reduce helper method
@results = @comments.map_reduce(map, reduce, :out => "mr_results")

# Since this method returns an instantiated results collection,
# we just have to query that collection and iterate over the cursor.
>> @results.find().to_a
=> [{"_id" => "hwaet",   "value"=>{"votes"=>21.0}}, 
    {"_id" => "kbanker", "value"=>{"votes"=>13.0}}
   ]
  • 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-22T23:47:33+00:00Added an answer on May 22, 2026 at 11:47 pm

    The new Map / Reduce output options are documented here.

    The basic premise is that Map / Reduce would originally just output to a temp collection. There were issues around the temp collection, (why do all of that work just to have it be temporary?) and there were some features added around merging and re-reducing.

    In particular, you can now run an M/R that effectively updates what output from a previous M/R. (think of updating daily stats once / hour and only processing the last hour).

    However, if you only want an in-memory version of the results, you can use the inline option.

    {out: { inline : 1}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following this example tutorial project code: http://akrabat.com/wp-content/uploads/zf-tutorial-layoutform.zip tutorial: http://akrabat.com/zend-framework/a-form-in-your-layout/ The project code runs
I copied this code from an example . I've read it 100 times. Array.prototype.map
I've been following this tutorial on how to create an OData service. http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx And
I have just compiled this code: http://www.win32developer.com/tutorial/winsock/winsock_tutorial_2.shtm I have added some codes so it
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
This is an example code from the prototype site. var url = '/proxy?url=' +
This is the BaseSpider example from the Scrapy tutorial: from scrapy.spider import BaseSpider from
I am following the C programming tutorial at http://www.cprogramming.com/tutorial/c/lesson10.html . This particular tutorial teaches
I was following instructions from a Java website ( http://java.sun.com/docs/books/tutorial/essential/io/file.html#createStream ) on creating or
There is a tutorial here: http://perishablepress.com/slide-fade-content/ and the code it provides is: $(document).ready(function(){ //

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.