@@ -1302,7 +1302,7 @@ def inline_map_reduce(self, map, reduce, full_response=False, **kwargs):
13021302 return res .get ("results" )
13031303
13041304 def find_and_modify (self , query = {}, update = None ,
1305- upsert = False , sort = None , ** kwargs ):
1305+ upsert = False , sort = None , full_response = False , ** kwargs ):
13061306 """Update and return an object.
13071307
13081308 This is a thin wrapper around the findAndModify_ command. The
@@ -1315,13 +1315,21 @@ def find_and_modify(self, query={}, update=None,
13151315 parameter. If no objects match the `query` and `upsert` is false,
13161316 returns ``None``. If upserting and `new` is false, returns ``{}``.
13171317
1318+ If the full_response parameter is true, the return value will be
1319+ the entire response object from the server, including the 'ok' and
1320+ 'lastErrorObject' fields, rather than just the modified object.
1321+ This is useful mainly because the 'lastErrorObject' document holds
1322+ information about the command's execution.
1323+
13181324 :Parameters:
13191325 - `query`: filter for the update (default ``{}``)
13201326 - `update`: see second argument to :meth:`update` (no default)
13211327 - `upsert`: insert if object doesn't exist (default ``False``)
13221328 - `sort`: a list of (key, direction) pairs specifying the sort
13231329 order for this query. See :meth:`~pymongo.cursor.Cursor.sort`
13241330 for details.
1331+ - `full_response`: return the entire response object from the
1332+ server
13251333 - `remove`: remove rather than updating (default ``False``)
13261334 - `new`: return updated rather than original object
13271335 (default ``False``)
@@ -1336,6 +1344,9 @@ def find_and_modify(self, query={}, update=None,
13361344
13371345 .. note:: Requires server version **>= 1.3.0**
13381346
1347+ .. versionchanged:: 2.5
1348+ Added the optional full_response parameter
1349+
13391350 .. versionchanged:: 2.4
13401351 Deprecated the use of mapping types for the sort parameter
13411352
@@ -1385,7 +1396,10 @@ def find_and_modify(self, query={}, update=None,
13851396 # Should never get here b/c of allowable_errors
13861397 raise ValueError ("Unexpected Error: %s" % (out ,))
13871398
1388- return out .get ('value' )
1399+ if full_response :
1400+ return out
1401+ else :
1402+ return out .get ('value' )
13891403
13901404 def __iter__ (self ):
13911405 return self
0 commit comments