Skip to content

Commit 341b2b5

Browse files
jaracoShaneHarvey
authored andcommitted
Document find_one_and_update return value on no match. (mongodb#361)
Trim excess whitespace.
1 parent 384796b commit 341b2b5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pymongo/collection.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
24312431
"""Watch changes on this collection.
24322432
24332433
Performs an aggregation with an implicit initial ``$changeStream``
2434-
stage and returns a
2434+
stage and returns a
24352435
:class:`~pymongo.change_stream.CollectionChangeStream` cursor which
24362436
iterates over changes on this collection.
24372437
@@ -2445,7 +2445,7 @@ def watch(self, pipeline=None, full_document='default', resume_after=None,
24452445
24462446
The :class:`~pymongo.change_stream.CollectionChangeStream` iterable
24472447
blocks until the next change document is returned or an error is
2448-
raised. If the
2448+
raised. If the
24492449
:meth:`~pymongo.change_stream.CollectionChangeStream.next` method
24502450
encounters a network error when retrieving a batch from the server,
24512451
it will automatically attempt to recreate the cursor such that no
@@ -3019,9 +3019,16 @@ def find_one_and_update(self, filter, update,
30193019
... {'_id': 665}, {'$inc': {'count': 1}, '$set': {'done': True}})
30203020
{u'_id': 665, u'done': False, u'count': 25}}
30213021
3022-
By default :meth:`find_one_and_update` returns the original version of
3023-
the document before the update was applied. To return the updated
3024-
version of the document instead, use the *return_document* option.
3022+
Returns ``None`` if no document matches the filter.
3023+
3024+
>>> db.test.find_one_and_update(
3025+
... {'_exists': False}, {'$inc': {'count': 1}})
3026+
3027+
When the filter matches, by default :meth:`find_one_and_update`
3028+
returns the original version of the document before the update was
3029+
applied. To return the updated (or inserted in the case of
3030+
*upsert*) version of the document instead, use the *return_document*
3031+
option.
30253032
30263033
>>> from pymongo import ReturnDocument
30273034
>>> db.example.find_one_and_update(
@@ -3080,8 +3087,7 @@ def find_one_and_update(self, filter, update,
30803087
document matches the query. Defaults to ``False``.
30813088
- `return_document`: If
30823089
:attr:`ReturnDocument.BEFORE` (the default),
3083-
returns the original document before it was updated, or ``None``
3084-
if no document matches. If
3090+
returns the original document before it was updated. If
30853091
:attr:`ReturnDocument.AFTER`, returns the updated
30863092
or inserted document.
30873093
- `array_filters` (optional): A list of filters specifying which

0 commit comments

Comments
 (0)