DocumentDB上的并发 [英] Concurrency on DocumentDB

查看:64
本文介绍了DocumentDB上的并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是DocumentDB上的一个新问题.我们想在我们的应用程序中使用DocumentDB.我们有多个用户正在更改存储在DocumentDB中的数据.我们如何确保一个用户不会覆盖另一个用户的更改?

This is a newby question on DocumentDB. We want to use DocumentDB for our application. We have multiple users changing data that is stored in a DocumentDB. How can we asure that one user does not overwrite the changes of another user?

推荐答案

DocumentDB不能防止并发.如果您在现有文档上发布新版本的文档,则旧文档将被覆盖.如果可以防止并发写入,则必须使用文档的时间戳. documentDB中的每个文档都有最后一个操作的时间戳.

DocumentDB does not protect against concurrency. If you post a new version of the document over an existing the old document will be overwritten. If you can to protect against concurrent writes you have to use the timestamp of the document. Every document in documentDB has a timestamp of the last action.

在每次更新时,您都可以检查要更新的文档的时间戳是否等于您检索的时间戳,或者该时间戳是否已更改.如果已更改,则用户没有最新版本,您可以取消更新.

On every update you can check if the timestamp of the document you want to update is equal to the one that you retrieved or if it has changed. If is has changed the user does not have the most recent version and you can cancel the update.

最好的办法是创建一个存储过程,以便您可以将此逻辑放入存储的proc中,并使您的应用程序与之无关.

The best thing is to create a stored procedure so you can put this logic inside a stored proc and make your application agnostic of it.

这篇关于DocumentDB上的并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆