#NEWLINE# def test__set_replace_subdocument_positional_operator( self ) : #NEWLINE# #INDENT# base_document = { #NEWLINE# #INDENT# 'int_field' : 1 , #NEWLINE# 'list_field' : [ { #NEWLINE# #INDENT# 'str_field' : 'a' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'str_field' : 'b' , #NEWLINE# 'int_field' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'str_field' : 'c' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# new_subdoc = { #NEWLINE# #INDENT# 'str_field' : 'x' , #NEWLINE# #UNINDENT# } #NEWLINE# self . db . collection . insert ( base_document ) #NEWLINE# self . db . collection . update ( { #NEWLINE# #INDENT# 'int_field' : 1 , #NEWLINE# 'list_field.str_field' : 'b' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'list_field.$' : new_subdoc , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# expected_document = copy . deepcopy ( base_document ) #NEWLINE# expected_document [ 'list_field' ] [ 1 ] = new_subdoc #NEWLINE# self . assertEqual ( list ( self . db . collection . find ( ) ) , [ expected_document ] )