Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3657

Not Properly Detecting Operation Conflict on Update

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I have a document with a couple of embedded relationships. When updating AND inserting the same kind of embeds_many with the updated one receiving a field update and additional embedded docs (images), mongoid is not properly computing the separate updates to make. The model looks something like this:

      model Content
      embeds many Content Blocks
      embeds many Content Assets

      In the first example below, I've added Content Assets to an existing Content Block and added a few new Content Blocks, that works fine. In the second example below that fails, I've updated a field in an existing Content Block, added Content Assets to it AND added additional Content Blocks. For some reason Mongoid doesn't split these out properly, and when safe mode is turned on we get this error – failed with error 10151: "have conflicting mods in update”

      THIS WORKS:
      17:00:00 web.1 | MOPED: 127.0.0.1:27017 UPDATE database=theline_development collection=clear_cms_contents selector=

      {"_id"=>"52585d3684cf810f72000cd7"} update={"$set"=>{"updated_at"=>2014-05-16 21:00:00 UTC}, "$pushAll"=>{"content_blocks.0.content_assets"=>[{"_id"=>"53767c50628c2d15c8000076", "path"=>"theline/2014/05/16", "file"=>"cropped_DSC_0014.JPG", "title"=>"cropped_DSC_0014.JPG", "description"=>"", "credit"=>"", "tags"=>[], "order"=>50, "width"=>"1736", "height"=>"1736"}], "content_logs"=>[{"_id"=>"53767c50628c2d15c8000078", "entry"=>"edited", "user_id"=>"5232282c75bda27c2b000008", "updated_at"=>2014-05-16 21:00:00 UTC, "created_at"=>2014-05-16 21:00:00 UTC}]}} flags=[] (0.6099ms)
      17:00:00 web.1 | MOPED: 127.0.0.1:27017 UPDATE database=theline_development collection=clear_cms_contents selector={"_id"=>"52585d3684cf810f72000cd7"}

      update={"$pushAll"=>{"content_blocks"=>[

      {"_id"=>"53767c50628c2d15c8000077", "type"=>"", "body"=>"", "order"=>nil, "has_gallery"=>false}

      ]}} flags=[] (0.2232m

      THIS ONE DOESN’T:
      16:56:48 web.1 | MOPED: 127.0.0.1:27017 UPDATE database=theline_development collection=clear_cms_contents selector=

      {"_id"=>"52585d3684cf810f72000cd7"} update={"$set"=>{"updated_at"=>2014-05-16 20:56:48 UTC, "content_blocks.0.body"=>"test"}, "$pushAll"=>{"content_logs"=>[{"_id"=>"53767b90628c2d8159000073", "entry"=>"edited", "user_id"=>"5232282c75bda27c2b000008", "updated_at"=>2014-05-16 20:56:48 UTC, "created_at"=>2014-05-16 20:56:48 UTC}]}} flags=[] (0.6571ms)
      16:56:48 web.1 | MOPED: 127.0.0.1:27017 UPDATE database=theline_development collection=clear_cms_contents selector={"_id"=>"52585d3684cf810f72000cd7"}

      update={"$pushAll"=>{"content_blocks.0.content_assets"=>[

      {"_id"=>"53767b90628c2d8159000071", "path"=>"theline/2014/05/16", "file"=>"cropped_DSC_0020.JPG", "title"=>"cropped_DSC_0020.JPG", "description"=>"", "credit"=>"", "tags"=>[], "order"=>50, "width"=>"1736", "height"=>"1736"}

      ], "content_blocks"=>[

      {"_id"=>"53767b90628c2d8159000072", "type"=>"", "body"=>"", "order"=>nil, "has_gallery"=>false}

      ]}} flags=[] (0.5341ms)

      Code versions:
      moped (1.5.2)
      origin (1.1.0)
      mongoid (3.1.6)

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            niedfelj niedfelj
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: