Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-17999

Regression between MongoDB 2.4 and 2.6

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.7
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide

      First insert a test document:

      db.test.insert({ _id: 'iJ7m2eW66eoGjR4tQ',
      nested: 
       [ { required: 
            { _id: 'phitZKwpTqiH76BWS',
              username: 'person2',
              displayName: 'Person 2',
              field1: 'Field 2 - 1',
              field2: 'Field 2 - 2' } },
         { required: 
            { _id: 'phitZKwpTqiH76BWS',
              username: 'person2',
              displayName: 'Person 2' } },
         { required: { _id: 'Pua8HHJQzBbRtua9W' } },
         { required: { _id: 'Pua8HHJQzBbRtua9W' } },
         { required: 
            { _id: 'phitZKwpTqiH76BWS',
              username: 'person2',
              displayName: 'Person 2',
              field1: 'wrong' } },
         { required: { _id: 'Pua8HHJQzBbRtua9W' } }
       ]})
      

      And then run the following update query:

      db.test.update({ 'nested.required._id': 'phitZKwpTqiH76BWS',
        nested: 
         { '$elemMatch': 
            { '$or': 
               [ { 'required._id': 'phitZKwpTqiH76BWS',
                   'required.username': { '$ne': 'person2' } },
                 { 'required._id': 'phitZKwpTqiH76BWS',
                   'required.displayName': { '$ne': 'Person 2' } },
                 { 'required._id': 'phitZKwpTqiH76BWS',
                   'required.field1': { '$ne': 'Field 2 - 1' } },
                 { 'required._id': 'phitZKwpTqiH76BWS',
                   'required.field2': { '$ne': 'Field 2 - 2' } } ] } } }, { '$set': 
         { 'nested.$.required.username': 'person2',
           'nested.$.required.displayName': 'Person 2',
           'nested.$.required.field1': 'Field 2 - 1',
           'nested.$.required.field2': 'Field 2 - 2' } })
      

      If you test number of affected documents with:

      db.runCommand({getLastError : 1})
      

      Then on MongoDB 2.4 it will return number of affected documents "1" for first two runs of the update query, and the third one will be 0. As expected.

      On MongoDB 2.6 update query will be returning:

      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
      

      And "getLastError" will be returning "1" despite not really updating any document. Here are two issues:

      Number of affected queries is 1 (node.js driver is reporting this as well) despite no document being really modified. This makes our code using this queries go into a loop because it is expecting that there are more things to still update (it is running the update query in a loop until there are no more changes done to the database).

      The second issue is that no document is updated despite one being matched. It is unclear why the same update modifier does not work on 2.6 anymore.

      Show
      First insert a test document: db.test.insert({ _id: 'iJ7m2eW66eoGjR4tQ' , nested: [ { required: { _id: 'phitZKwpTqiH76BWS' , username: 'person2' , displayName: 'Person 2' , field1: 'Field 2 - 1' , field2: 'Field 2 - 2' } }, { required: { _id: 'phitZKwpTqiH76BWS' , username: 'person2' , displayName: 'Person 2' } }, { required: { _id: 'Pua8HHJQzBbRtua9W' } }, { required: { _id: 'Pua8HHJQzBbRtua9W' } }, { required: { _id: 'phitZKwpTqiH76BWS' , username: 'person2' , displayName: 'Person 2' , field1: 'wrong' } }, { required: { _id: 'Pua8HHJQzBbRtua9W' } } ]}) And then run the following update query: db.test.update({ 'nested.required._id' : 'phitZKwpTqiH76BWS' , nested: { '$elemMatch' : { '$or' : [ { 'required._id' : 'phitZKwpTqiH76BWS' , 'required.username' : { '$ne' : 'person2' } }, { 'required._id' : 'phitZKwpTqiH76BWS' , 'required.displayName' : { '$ne' : 'Person 2' } }, { 'required._id' : 'phitZKwpTqiH76BWS' , 'required.field1' : { '$ne' : 'Field 2 - 1' } }, { 'required._id' : 'phitZKwpTqiH76BWS' , 'required.field2' : { '$ne' : 'Field 2 - 2' } } ] } } }, { '$set' : { 'nested.$.required.username' : 'person2' , 'nested.$.required.displayName' : 'Person 2' , 'nested.$.required.field1' : 'Field 2 - 1' , 'nested.$.required.field2' : 'Field 2 - 2' } }) If you test number of affected documents with: db.runCommand({getLastError : 1}) Then on MongoDB 2.4 it will return number of affected documents "1" for first two runs of the update query, and the third one will be 0. As expected. On MongoDB 2.6 update query will be returning: WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 }) And "getLastError" will be returning "1" despite not really updating any document. Here are two issues: Number of affected queries is 1 (node.js driver is reporting this as well) despite no document being really modified. This makes our code using this queries go into a loop because it is expecting that there are more things to still update (it is running the update query in a loop until there are no more changes done to the database). The second issue is that no document is updated despite one being matched. It is unclear why the same update modifier does not work on 2.6 anymore.

      When testing upgrading of our codebase to 2.6 from 2.4 some of our tests started failing. After analyzing tests we found a sample of failing update query which worked well on 2.4 but does not work as expected anymore on 2.6.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            mitar NOVALUE Mitar
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: