I know that I can\'t lock a single mongodb document, in fact there is no way to lock a collection either.
However, I\'ve got this scenario, where I think I need some
Classic solution when you want to make something thread-safe is to use locks (mutexes). This is also called pessimistic locking as opposed to optimistic locking described here.
There are scenarios when pessimistic locking is more efficient (more details here). It is also far easier to implement (major difficulty of optimistic locking is recovery from collision).
MongoDB does not provide mechanism for a lock. But this can be easily implemented at application level (i.e. in your code):
The granularity of the lock can be different: global, collection-specific, record/document-specific. The more specific the lock the less its performance penalty.