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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:01:09+00:00 2026-05-24T12:01:09+00:00

So my friend and I are trying to do a map reduce on a

  • 0

So my friend and I are trying to do a map reduce on a collection that has items being added to it consistently.

Basically we calculate the average of some fields and put them in a collection (via map reduce).

Here is the issue, every time map reduce is ran it goes through ALL of the documents. I’m new to map reduce, but based on what I know it seems that it would be super efficient if it only ran map reduce on the new and/or modified documents and update them with the existing collection.

So I was like OK, I’ll just do it myself. Added a “processed: false” to the collection, and when the map reduce runs I pass in a query filter “{processed:false}” then after the map reduce runs I then set “{processed:true}” to all the items where processed = false.

Here is the issue. I am worried about edge case. What happens if during the map reduce some items are added to the collection? They were never passed into the map reduce, and now after the map reduce runs their processed flag is set to true.

What would be great is if instead of passing in a “query filter” into mongo, that I would be able to pass in a query object “set” So then I can set the processed flag to true and then pass in those objects.

  • 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-24T12:01:10+00:00Added an answer on May 24, 2026 at 12:01 pm

    Make it a 3 step thing. Have 3 states, say UNPROCESSED, MARKEDFORPROCESSING and PROCESSED, then :

    1. db.col.update({processingState:UNPROCESSED}, {$set:{processingState:MARKEDFORPROCESSING}}, false, true)
    2. Run m/r against MARKEDFORPROCESSING documents. These are guaranteed to have been there at m/r start.
    3. db.col.update({processingState:MARKEDFORPROCESSING }, {$set:{processingState:PROCESSED}}, false, true)
    4. Go to 1.

    This avoids your edge case and given MongoDB’s atomic updates is completely safe.

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

Sidebar

Related Questions

My friend is trying to create a utility function that is given some Type
I'm currently trying to extend a friend's OCaml program. It's a huge collection of
I have a GPSTestViewController class that has a MKMapView with added MKAnnotations (stored in
Trying to help a friend out with a friend out with some assembly code,
I'm trying to create some 'friend assemblies' using the [InternalsVisibleTo()] attribute, but I can't
I'm trying to map some data (returned from a jQuery $.ajax call) to a
My friend is trying to write a Windows application that can query an iPhone
Me and my friend are trying to make a webpage which has a flash
Lets say that me and my friend are trying to work on same software
Im trying to call the function: friend ostream& operator<<(ostream& out, stack::myItem& theItem); that is

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.