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

nModified should be 0 when a write error occurs.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-rc1
    • Fix Version/s: 2.6.0-rc2
    • Component/s: Write Ops
    • Labels:
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      When an update command results in a writeError (e.g. duplicate key) the nModified field is no longer returned (tested against master, standalone):

      >>> c.test.test.create_index('a', unique=True)
      u'a_1'
      >>> c.test.command('insert', 'test', documents=[{'_id': 1, 'a': 1}])
      {u'ok': 1, u'n': 1}
      >>> c.test.command('insert', 'test', documents=[{'_id': 2}])
      {u'ok': 1, u'n': 1}
      >>> try:
      ...     c.test.command('update', 'test', updates=[SON([('q', {'_id':
      2}), ('u', {'$set': {'a': 1}}), ('upsert', False), ('multi',
      False)])])
      ... except Exception, exc:
      ...     print exc.details
      ...
      {u'writeErrors': [{u'index': 0, u'code': 11000, u'errmsg': u'E11000
      duplicate key error index: test.test.$a_1  dup key: { : 1 }'}], u'ok':
      1, u'n': 0}

      Rolling mongo master back about a day, we have this behavior (which I think is correct):

      >>> try:
      ...     c.test.command('update', 'test', updates=[SON([('q', {'_id':
      2}), ('u', {'$set': {'a': 1}}), ('upsert', False), ('multi',
      False)])])
      ... except Exception, exc:
      ...     print exc.details
      ...
      {u'nModified': 0, u'writeErrors': [{u'index': 0, u'code': 11000,
      u'errmsg': u'E11000 duplicate key error index: test.test.$a_1  dup
      key: { : 1 }'}], u'ok': 1, u'n': 0}

      Show
      When an update command results in a writeError (e.g. duplicate key) the nModified field is no longer returned (tested against master, standalone): >>> c.test.test.create_index('a', unique=True) u'a_1' >>> c.test.command('insert', 'test', documents=[{'_id': 1, 'a': 1}]) {u'ok': 1, u'n': 1} >>> c.test.command('insert', 'test', documents=[{'_id': 2}]) {u'ok': 1, u'n': 1} >>> try: ... c.test.command('update', 'test', updates=[SON([('q', {'_id': 2}), ('u', {'$set': {'a': 1}}), ('upsert', False), ('multi', False)])]) ... except Exception, exc: ... print exc.details ... {u'writeErrors': [{u'index': 0, u'code': 11000, u'errmsg': u'E11000 duplicate key error index: test.test.$a_1 dup key: { : 1 }'}], u'ok': 1, u'n': 0} Rolling mongo master back about a day, we have this behavior (which I think is correct): >>> try: ... c.test.command('update', 'test', updates=[SON([('q', {'_id': 2}), ('u', {'$set': {'a': 1}}), ('upsert', False), ('multi', False)])]) ... except Exception, exc: ... print exc.details ... {u'nModified': 0, u'writeErrors': [{u'index': 0, u'code': 11000, u'errmsg': u'E11000 duplicate key error index: test.test.$a_1 dup key: { : 1 }'}], u'ok': 1, u'n': 0}

      Description

      This is related to SERVER-13001. In that ticket it was decided to not report nModified if a legacy shard primary is part of an update operation. It would appear that the changes for that ticket also removed nModified if a write error occurs (e.g. duplicate key error), even with a standalone mongod. nModified should be 0 in this case, just like 'n'.

      This change makes it hard for drivers to differentiate when they should not report nModified (the result was at least in part from a legacy server) and when they should (all other cases).

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: