MongoDB:可以在文档中使用第二个 objectID 用于更新时的并发检查吗?
是否可以在文档中使用第二个 objectID 来测试更新的并发性?
项目:Microsoft MVC2 / C# / Mongo 1.6 / 10Gen C# 驱动程序 (v0.9.0)
我正在尝试解决并发问题(和 NOSQL 存储库)。这是我在关系数据库之外的第一个项目,我不知道与 Mongo 并发的实践是什么。
过去的项目(SQL Server)围绕时间戳列包装并发检查/
谢谢
Is it OK to use a second objectID in a document to use to test concurrency on an update?
Project: Microsoft MVC2 / C# / Mongo 1.6 / 10Gen C# driver (v0.9.0)
I'm trying to wrap my head around concurrency issues (and NOSQL repository). This is my first project outside of a relational database and I don't know what the practice is around concurrency with Mongo.
Past projects (SQL Server) wrapped concurrency check around a timestamp column/
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,MongoDB 文档有一整个关于并发的页面。
这里的关键实际上是“您想要什么类型的并发?”并发有大量您真正需要考虑的边缘情况。
使用 _id + 时间戳的概念绝对可以在 MongoDB 中工作(或任何形式的唯一“this was Updated” 键)。编辑:请查看“findAndModify”上的文档,这可能就是您想要的。
MongoDB 拥有一整套很酷的并发功能,主要围绕它的更新方式。特别是,请参阅有关更新修饰符的部分。这些特殊操作是“单个文档上的原子操作”,并且它们往往可以处理许多常见情况。
想要增加一个变量吗?使用
$inc
,如果该字段不存在,它甚至会创建该字段。有一系列内容并且只想在不存在的情况下添加内容?使用$addToSet
命令。 Mongo 有大量这样的数组操作。这些并不完全处于 _id+timestamp 级别,但它们确实处理并发控制的几种常见情况。
So the MongoDB docs have a whole page on concurrency.
The big key here is really "what type of concurrency do you want?" Concurrency has a ton of edge cases that you really need to consider.
The concept of using _id + timestamp can definitely work in MongoDB (or any form of unique "this was updated" key). EDIT: Please check out this doc on "findAndModify" which is probably what you want.
MongoDB has a whole host of cool concurrency features centered around how it does updates. In particular, please see this section on Update Modifiers. These special operations are "atomic on a single document" and they tend to handle a lot of common cases.
Want to increment a variable? Use
$inc
, it will even create the field if it doesn't exist. Have an array of stuff and want to add something only if it doesn't exist? Use the$addToSet
command. Mongo has a whole host of such array operations.These are not quite at the level of _id+timestamp, but they do handle several common cases for concurrency control.