title: Mongodb atomic schema-planning
body: <p>My program has users and groups.
  Use-case: Users have credits they can give to the groups.</p>
  
  <p>I want no credits to be lost.</p>
  
  <p>The problem with RDBMS-like schema is the atomicity of Mongo is document-level. I reduce the credits of the user and then increase the credits of the group. If the application crashes between the two the credits, that are sent, become lost. (If I replace the two actions credits can appear without being withdrawn from the user.)</p>
  
  <p>One solution could be using of a collection called transactions. Then the credits of the user can be calculated from the send credits of the user subtracted from the credits of the user. The credits of the group can be calculated as the sum of the sent credits. The problem is if the database grows the sum will take a while.</p>
  
  <p>Can you give me any acceptable, scalable and robust solution for this with NoSQL? (I know it is really easy in RDBMS)</p>