开发者

CouchDb and data writes

As I understand it CouchDb never overwrites a record but instead creates a new document with a new _rev. What happens in this scenario?

开发者_如何学运维
  1. User A reads a document
  2. User B reads the same document
  3. User A updates the document
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜