As I understand it CouchDb never overwrites a record but instead creates a new document with a new _rev. What happens in this scenario?
开发者_如何学运维- User A reads a document
- User B reads the same document
- User A updates the document
- User B updates the document
Aren't User A's changes lost in this scenario?
No, instead User B will get a 409 error since the revs will no longer match. For User B to commit their document, they will need refetch the document so they can get the latest document revision.
This is called Optimistic Locking, and is designed to specifically prevent the problem that you are seeing.
There's nothing stopping User B from stomping on User A's document, but now they are more conscious of it by having to refetch the document and use the new _rev parameter.
精彩评论