Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2972

Calling find_one_and_* methods with write_concern 0 causes an error

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.18.0
    • Affects Version/s: None
    • Component/s: None
    • None

      The find_one_and_* methods automatically get the first element from the result and get the value for the key "value". When write_concern is {{

      {w:0}

      }} only the empty list is returned, and this leads to the following error:

      #<NoMethodError: undefined method `[]' for nil:NilClass>
      

      This can be reproduced using the following code:

      context 'when unacknowledged writes is used on find_one_and_update' do
      
          let(:selector) do
            { name: 'BANG' }
          end
      
          let(:collection_with_unacknowledged_write_concern) do
            authorized_collection.with(write: { w: 0 })
          end
      
          let(:result) do
            collection_with_unacknowledged_write_concern.find_one_and_update(selector,
              { '$set' => { field: 'testing' }},
              write_concern: { w: 0 })
          end
      
          it 'does not raise an exception' do
            expect(result.inserted_count).to be(0)
          end
        end
      

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: