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

Complex document updates can fail with op conflict

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0
    • Affects Version/s: 5.0.0
    • Component/s: None
    • None

      I received an error `Cannot update 'nested.0.further_nested' and 'nested' at the same time (16837)` when calling `document.save!`. There were many update commands that succeeded and the one that failed was $pushAll on both 'nested.0. further_nested' and 'nested', i.e. modifying the first nested document as well as adding more nested documents on the same level.

      I believe this should be responsibility of Mongoid and not the application code to separate these updates into acceptable operations.

      This github issue might be related:
      https://github.com/mongodb/mongoid/pull/3200

      Stack trace:

      /usr/local/lib/ruby/gems/2.2.0/gems/mongo-2.1.0.rc0/lib/mongo/operation/result.rb:214:in `validate!': Cannot update 'nested.0.further_nested' and 'nested' at the same time (16837) (Mongo::Error::OperationFailure)
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongo-2.1.0.rc0/lib/mongo/operation/write/write_command_enabled.rb:48:in `execute_write_command'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongo-2.1.0.rc0/lib/mongo/operation/write/write_command_enabled.rb:38:in `execute'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongo-2.1.0.rc0/lib/mongo/collection/view/writable.rb:186:in `update'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongo-2.1.0.rc0/lib/mongo/collection/view/writable.rb:163:in `update_one'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/query_cache.rb:168:in `update_one_with_clear_cache'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:146:in `block (2 levels) in update_document'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:145:in `each_pair'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:145:in `block in update_document'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:118:in `block (2 levels) in prepare_update'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:88:in `run_callbacks'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/interceptable.rb:138:in `run_callbacks'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:117:in `block in prepare_update'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:115:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:553:in `block (2 levels) in compile'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:503:in `call'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/callbacks.rb:88:in `run_callbacks'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/interceptable.rb:138:in `run_callbacks'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:116:in `prepare_update'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/updatable.rb:139:in `update_document'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/savable.rb:25:in `save'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/mongoid-5.0.0.rc0/lib/mongoid/persistable/savable.rb:44:in `save!'
      	from /Users/amw/Dropbox/Projects/data-harvest/lib/mpt/facet_client.rb:173:in `import_data'
      	from /Users/amw/Dropbox/Projects/data-harvest/lib/mpt/facet_client.rb:58:in `block in import_data_for_sample'
      	from /Users/amw/Dropbox/Projects/data-harvest/app/models/sample.rb:177:in `process_in_batch'
      	from /Users/amw/Dropbox/Projects/data-harvest/lib/mpt/facet_client.rb:57:in `import_data_for_sample'
      	from test_facet.rb:7:in `<top (required)>'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/runner.rb:60:in `load'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/runner.rb:60:in `<top (required)>'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:90:in `runner'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
      	from /Users/amw/Dropbox/Projects/data-harvest/bin/rails:8:in `<top (required)>'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
      	from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
      	from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      	from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      	from -e:1:in `<main>'
      

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            amw Adam Wróbel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: