Concurrent access to a document with mongoose Concurrent access to a document with mongoose mongoose mongoose

Concurrent access to a document with mongoose


Yes the last change will win.

A queue could be a good option to solve the problem but I'll suggest 2 other ways:

  1. You could use more advanced mongodb commands, such as $inc (http://docs.mongodb.org/manual/reference/operator/update/inc/) to compute attomically (if your computation are too complicated maybe it is not possible)
  2. If you don't necessarily need to have the correct count available at any time, you could use a 'big data' approach and just store the raw clicks information.Whenever you need the data (or say every hour or day), you could then use the mongodb aggregate framework, or their mapreduce feature, to compute the correct count.