MongoDB has nothing to do with optimistic concurrency. You must implement this yourself if you need it.
This can be done by adding a timestamp DateTime, reading it before performing the upgrade, and using this timestamp as a filter for updating. If the timestamp has been changed before you had the opportunity to update, than the update operation will not be able to find the document.
For example:
UpdateResult updateResult;
do
{
var document = await collection.Find(_ => _.Id == id).SingleAsync();
updateResult = await collection.UpdateOneAsync(_ => _.Id == id && _.TimeStamp == document.TimeStamp, Builders<Item>.Update...);
} while (updateResult.ModifiedCount == 0);
source
share