【问题标题】:simulate mongodb race condition模拟 mongodb 竞争条件
【发布时间】:2019-03-21 01:48:49
【问题描述】:

我从旧代码中获得了"Error: error occured while saving model: VersionError: No matching document found for id "5bb83342342342348a5"

(相关:"VersionError: No matching document found" error on Node.js/Mongoose

问题是由于保存了一个非常大的数据集(几场演出,花了 2 天时间创建)。

现在,我正在尝试重现错误,但我不想花费 2~4 天的时间来重现事情。有没有办法人为地延长锁定-解锁阶段?

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    您要做的是保存自检索后已修改的文档。以下是如何重现它的示例:

    // Get the same document twice
    const data1 = await model.findOne(...);
    const data2 = await model.findOne(...);
    
    data1.someField = x;
    data2.someField = y;
    
    await data1.save();
    
    // save is going to throw
    await data2.save();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-02
      • 1970-01-01
      • 2022-01-23
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多