[SERVER-13210] nModified should be 0 when a write error occurs. Created: 14/Mar/14  Updated: 11/Jul/16  Resolved: 18/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0-rc1
Fix Version/s: 2.6.0-rc2

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-145 Don't include the nModified field in ... Closed
Related
is related to SERVER-13001 exclude nModified from legacy write r... Closed
Operating System: ALL
Steps To Reproduce:

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}

Participants:

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



 Comments   
Comment by Githook User [ 18/Mar/14 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-13210: include nModified for all mongod write commands
Branch: master
https://github.com/mongodb/mongo/commit/e200a2274f34ba016a123cc4bc943dfe22426e93

Comment by Githook User [ 18/Mar/14 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-13210: include nModified for all mongod write commands

(cherry picked from commit e200a2274f34ba016a123cc4bc943dfe22426e93)
Branch: v2.6
https://github.com/mongodb/mongo/commit/72e9bea86f89097fb65b9d392230235069302e96

Generated at Thu Feb 08 03:30:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.