Skip to content

Commit 12d628b

Browse files
committed
PYTHON-328 - Added support as_class in find_and_modify
1 parent d09f3db commit 12d628b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pymongo/database.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ def command(self, command, value=1,
314314
- `**kwargs` (optional): additional keyword arguments will
315315
be added to the command document before it is sent
316316
317+
.. versionchanged:: 2.1.1+
318+
Added support for `as_class` - the class you want to use for
319+
the resulting documents
317320
.. versionchanged:: 1.6
318321
Added the `value` argument for string commands, and keyword
319322
arguments for additional command options.
@@ -328,6 +331,7 @@ def command(self, command, value=1,
328331
command = SON([(command, value)])
329332

330333
extra_opts = {
334+
'as_class': kwargs.pop('as_class', None),
331335
'read_preference': kwargs.pop('read_preference',
332336
self.read_preference),
333337
'slave_okay': kwargs.pop('slave_okay', self.slave_okay),

test/test_collection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,17 @@ def test_find_and_modify(self):
15271527
c.find_and_modify({'_id': 1}, {'$inc': {'i': 1}},
15281528
new=True, fields={'i': 1}))
15291529

1530+
class ExtendedDict(dict):
1531+
pass
1532+
1533+
result = c.find_and_modify({'_id': 1}, {'$inc': {'i': 1}},
1534+
new=True, fields={'i': 1})
1535+
self.assertFalse(isinstance(result, ExtendedDict))
1536+
result = c.find_and_modify({'_id': 1}, {'$inc': {'i': 1}},
1537+
new=True, fields={'i': 1},
1538+
as_class=ExtendedDict)
1539+
self.assertTrue(isinstance(result, ExtendedDict))
1540+
15301541
def test_find_with_nested(self):
15311542
if not version.at_least(self.db.connection, (2, 0, 0)):
15321543
raise SkipTest()

0 commit comments

Comments
 (0)