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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:25:45+00:00 2026-05-31T05:25:45+00:00

So my map reduce operation sums up a list of micro payments into a

  • 0

So my map reduce operation sums up a list of micro payments into a lump sum that I owe a particular user. The user_id ends up being the _id. I also store an array ids of the micro payments that need to be paid. The output goes into a permeant collection called payments.

The output looks like this for one document

{ "_id" : ObjectId("4f48855606164f4765000004"), "value" : { "payment" : "5.0", "conversions" : [ ObjectId("4f5bd23baa113e964700000e") ] } }

I’d kind of like to track these payments so I was thinking about just building a mongoid document around the payments collection. I kind of know it can be done but I haven’t really seen anyone doing it so it makes me think there must be a better way.

Also one problem with this approach is I’m making the payments every month so the _id being the user_id is going to conflict. Additionally I think there is a possible transaction problem because I need to update the micro payments to a different state so I know not to pay them ever again and what happens if one of the payments fails? These state change via state_machine if that makes any difference.

  • 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-31T05:25:46+00:00Added an answer on May 31, 2026 at 5:25 am

    Should I be accessing Map Reduce output as a Mongoid Document?

    Sure you can definitely do this. That’s kind of the reason the M/R is output to a collection rather than just “some file”.

    Also one problem with this approach is I’m making the payments every month so the _id being the user_id is going to conflict.

    So clearly, the output of your M/R is important data. Do not leave this data in a collection that could be “hammered” by a future M/R. Instead, rename the collection you have created, or run a for loop that manually appends the data to a “keeper” collection.

    In the “keeper” collection change the _id to something like _id: { uid: ObjectId('...'), month: "201203" }. You may also want to “fan out” the values field into several fields. And you will need to add a field for transaction ID.

    Also remember that MongoDB uses “fire & forget” writes by default. These are low safety. You have financial data, so ensure that you are following all of the best practices for availability and data safety:

    • Journaling On
    • Replica Sets (with secondary data center)
    • Ensure that all writes to this collection/db are done with w: majority and journal: true. This will slow down DB throughput on this operation as these writes can take a few hundred milliseconds.
    • Database passwords
    • Non-standard MongoDB port, IP white-listing (usual DB security)

    what happens if one of the payments fails?

    This a non-trivial problem and way too complicated to explain here. Instead, see this document on the two-phase commit with MongoDB.

    Note that two-phase commit requires MongoDB’s findAndModify command. You will have to learn how to handle this with Mongoid.

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

Sidebar

Related Questions

Map Reduce is a pattern that seems to get a lot of traction lately
I know about map/reduce alghoritm and its use. It's using functions that are called
I have a simple map/reduce job that scans one hbase table, and modifies another
I am having difficulties getting a map / reduce operation to work. I'm a
For any key used in a map reduce operation, elements with can key may
I wrote a simple map reduce job that would read in data from the
Map reduce/Hadoop is one of the framework/program that s used for distributed systems. What
I've been reading about map/reduce so that I can improve my understanding of big
I've to perform a map reduce operation with a clustering algorithm of a large
Need a map reduce function by mongo in php This my mongo structure [_id]

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.