【问题标题】:MongoDB: enforcing sequential execution of inserts and updatesMongoDB:强制顺序执行插入和更新
【发布时间】:2014-01-09 11:28:35
【问题描述】:

我正在对 MongoDB 进行两次连续写入(无分片,无副本):

  1. 将数据插入数据库
  2. 查找并修改插入 1 中的数据。

在执行步骤 2) 时,是否允许该命令查看步骤 1) 中的数据插入?为了确保这一点,我应该在步骤 1) 中使用的最小 WriteConcern 是多少?

至于我的用例,我知道,我可以将 1 和 2 合并为一个简单的步骤;但是,我的实际用例要复杂得多,不能这么容易解决。

【问题讨论】:

    标签: mongodb transactions atomic getlasterror


    【解决方案1】:

    如果您使用Acknowledged 的写关注点,您的用例将起作用。这是 MongoDB 2.2 或更高版本中的默认写入问题,因为您使用的是最新的驱动程序 (see here for the minimum driver version required)。

    http://docs.mongodb.org/manual/release-notes/drivers-write-concern/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2010-12-23
      • 2017-07-30
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多