#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def _new_find_and_modify( self , filter , projection , sort , upsert = None , return_document = ReturnDocument . BEFORE , **kwargs ) : #NEWLINE# #INDENT# validate_is_mapping ( 'filter' , filter ) #NEWLINE# if ( not isinstance ( return_document , bool ) ) : #NEWLINE# #INDENT# raise ValueError ( 'TxMongo: return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER' ) #NEWLINE# #UNINDENT# cmd = SON ( [ ( 'findAndModify' , self . _collection_name ) , ( 'query' , filter ) , ( 'new' , return_document ) ] ) #NEWLINE# cmd . update ( kwargs ) #NEWLINE# if ( projection is not None ) : #NEWLINE# #INDENT# cmd [ 'fields' ] = self . _normalize_fields_projection ( projection ) #NEWLINE# #UNINDENT# if ( sort is not None ) : #NEWLINE# #INDENT# cmd [ 'sort' ] = dict ( sort [ 'orderby' ] ) #NEWLINE# #UNINDENT# if ( upsert is not None ) : #NEWLINE# #INDENT# validate_boolean ( 'upsert' , upsert ) #NEWLINE# cmd [ 'upsert' ] = upsert #NEWLINE# #UNINDENT# no_obj_error = 'No matching object found' #NEWLINE# result = ( yield self . _database . command ( cmd , allowable_errors = [ no_obj_error ] , ** kwargs ) ) #NEWLINE# defer . returnValue ( result . get ( 'value' ) )