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

nModified should be 0 when a write error occurs.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc2
    • Affects Version/s: 2.6.0-rc1
    • Component/s: Write Ops
    • ALL
    • 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}

      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).

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: