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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:22:52+00:00 2026-06-01T17:22:52+00:00

I tried to pass the collection to be update as a scope variable –

  • 0

I tried to pass the collection to be update as a scope variable – no dice.
I tried to invoke db.getCollection from the finalize body – no dice, I get this:

db assertion failure, assertion: 'invoke failed: JS Error: TypeError: db has no properties nofile_b:18', assertionCode: 9004

I guess it means that db is undefined within a finalize method. So, is it possible?

EDIT

Here is my finalize method:

function(key, value) {
  function flatten(value, collector) {
    var items = value;
    if (!(value instanceof Array)) {
      if (!value.items) {
        collector.push(value);
        return;
      }

      items = value.items;
    }
    for (var i = 0; i < items.length && collector.length < max_group_size; ++i) {
      flatten(items[i], collector);
    }
  }

  var collector = [];
  flatten(value, collector);
  return collector;
}

I would like to replace collector.push(value) with insert into some collection.

  • 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-01T17:22:53+00:00Added an answer on June 1, 2026 at 5:22 pm

    It is not possible to modify another collection from inside a Map/Reduce/Finalize function.

    Here is a link to a question from a user with a similar question. The answer, unfortunately, is “no”.
    How to change the structure of MongoDB's map-reduce results?

    Part of a reason for this is that MapReduce is designed to work in a sharded environment. The computations are distributed among the different shards, and the results are then aggregated. If each function running on each shard was allowed to modify collections, then each shard could end up with different data.

    If you would like a separate collection to be modified as a result of a Map Reduce operation, the best strategy is to run the Map Reduce operation, get the results, and then have your application update the separate collection.

    If you would like the results of multiple Map Reduce operations to be merged, it is possible to do this via an incremental Map Reduce. The documentation on this may be found here: http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-IncrementalMapreduce

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

Sidebar

Related Questions

I tried to pass a string in to get a reversed string. Why can't
Is it possible to pass a variable to a linked .js file? I tried
I want to pass the values from MapOverlay class to another class. I tried
I am trying to pass a variable within a header link. I have tried
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
I'm working with XML and Flash. I tried to pass XML values to my
How do you pass a parameter into an include file? I tried the following
Is it possible to pass some variables to the called function, it tried it
Tried a bunch of things but I can't get it to work consistently amid
I would like to apologize if the duplicate of this question exist. i tried

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.