Skip to content

Commit af446e4

Browse files
committed
Verify reporting of nModified from collection.update(), PYTHON-648.
1 parent 4b30644 commit af446e4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/test_collection.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,24 @@ def transform_incoming(self, son, collection):
11441144
{'_id': 1, 'a': 3, 'field': 'value'},
11451145
db.test.find_one())
11461146

1147+
def test_update_nmodified(self):
1148+
db = self.db
1149+
db.drop_collection("test")
1150+
used_write_commands = (self.client.max_wire_version > 1)
1151+
1152+
db.test.insert({'_id': 1})
1153+
result = db.test.update({'_id': 1}, {'$set': {'x': 1}})
1154+
if used_write_commands:
1155+
self.assertEqual(1, result['nModified'])
1156+
else:
1157+
self.assertFalse('nModified' in result)
1158+
1159+
# x is already 1.
1160+
result = db.test.update({'_id': 1}, {'$set': {'x': 1}})
1161+
if used_write_commands:
1162+
self.assertEqual(0, result['nModified'])
1163+
else:
1164+
self.assertFalse('nModified' in result)
11471165

11481166
def test_multi_update(self):
11491167
db = self.db

0 commit comments

Comments
 (0)