#NEWLINE# def test__find_one_and_update( self ) : #NEWLINE# #INDENT# documents = [ { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# 's' : 0 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# 's' : 1 , #NEWLINE# #UNINDENT# } ] #NEWLINE# self . db . collection . insert_many ( documents ) #NEWLINE# self . assert_documents ( documents , ignore_ids = False ) #NEWLINE# doc = self . db . collection . find_one_and_update ( { #NEWLINE# #INDENT# 's' : 3 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'x' : 2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertIsNone ( doc ) #NEWLINE# self . assert_documents ( documents , ignore_ids = False ) #NEWLINE# doc = self . db . collection . find_one_and_update ( { #NEWLINE# #INDENT# 's' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'x' : 2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertDictEqual ( doc , documents [ 1 ] ) #NEWLINE# doc = self . db . collection . find_one_and_update ( { #NEWLINE# #INDENT# 's' : 3 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'x' : 3 , #NEWLINE# 's' : 2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , upsert = True ) #NEWLINE# self . assertIsNone ( doc ) #NEWLINE# self . assertIsNotNone ( self . db . collection . find_one ( { #NEWLINE# #INDENT# 'x' : 3 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if _HAVE_PYMONGO : #NEWLINE# #INDENT# update = { #NEWLINE# #INDENT# 'x' : 4 , #NEWLINE# 's' : 1 , #NEWLINE# #UNINDENT# } #NEWLINE# doc = self . db . collection . find_one_and_update ( { #NEWLINE# #INDENT# 's' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : update , #NEWLINE# #UNINDENT# } , return_document = ReturnDocument . AFTER ) #NEWLINE# doc . pop ( '_id' ) #NEWLINE# self . assertDictEqual ( documents , update )