@@ -3310,7 +3310,7 @@ async def find_one_and_delete(
33103310 let : Optional [Mapping [str , Any ]] = None ,
33113311 comment : Optional [Any ] = None ,
33123312 ** kwargs : Any ,
3313- ) -> _DocumentType :
3313+ ) -> Optional [ _DocumentType ] :
33143314 """Finds a single document and deletes it, returning the document.
33153315
33163316 >>> await db.test.count_documents({'x': 1})
@@ -3320,6 +3320,10 @@ async def find_one_and_delete(
33203320 >>> await db.test.count_documents({'x': 1})
33213321 1
33223322
3323+ Returns ``None`` if no document matches the filter.
3324+
3325+ >>> await db.test.find_one_and_delete({'_exists': False})
3326+
33233327 If multiple documents match *filter*, a *sort* can be applied.
33243328
33253329 >>> async for doc in db.test.find({'x': 1}):
@@ -3402,10 +3406,22 @@ async def find_one_and_replace(
34023406 let : Optional [Mapping [str , Any ]] = None ,
34033407 comment : Optional [Any ] = None ,
34043408 ** kwargs : Any ,
3405- ) -> _DocumentType :
3409+ ) -> Optional [ _DocumentType ] :
34063410 """Finds a single document and replaces it, returning either the
34073411 original or the replaced document.
34083412
3413+ >>> await db.test.find_one({'x': 1})
3414+ {'_id': 0, 'x': 1}
3415+ >>> await db.test.find_one_and_replace({'x': 1}, {'y': 2})
3416+ {'_id': 0, 'x': 1}
3417+ >>> await db.test.find_one({'x': 1})
3418+ >>> await db.test.find_one({'y': 2})
3419+ {'_id': 0, 'y': 2}
3420+
3421+ Returns ``None`` if no document matches the filter.
3422+
3423+ >>> await db.test.find_one_and_replace({'_exists': False}, {'x': 1})
3424+
34093425 The :meth:`find_one_and_replace` method differs from
34103426 :meth:`find_one_and_update` by replacing the document matched by
34113427 *filter*, rather than modifying the existing document.
@@ -3510,13 +3526,17 @@ async def find_one_and_update(
35103526 let : Optional [Mapping [str , Any ]] = None ,
35113527 comment : Optional [Any ] = None ,
35123528 ** kwargs : Any ,
3513- ) -> _DocumentType :
3529+ ) -> Optional [ _DocumentType ] :
35143530 """Finds a single document and updates it, returning either the
35153531 original or the updated document.
35163532
3533+ >>> await db.test.find_one({'_id': 665})
3534+ {'_id': 665, 'done': False, 'count': 25}
35173535 >>> await db.test.find_one_and_update(
35183536 ... {'_id': 665}, {'$inc': {'count': 1}, '$set': {'done': True}})
3519- {'_id': 665, 'done': False, 'count': 25}}
3537+ {'_id': 665, 'done': False, 'count': 25}
3538+ >>> await db.test.find_one({'_id': 665})
3539+ {'_id': 665, 'done': True, 'count': 26}
35203540
35213541 Returns ``None`` if no document matches the filter.
35223542
0 commit comments