def upsert(self, cfg, triggers_on=True):
input_object = cfg[AccessParams.KEY_OBJECT]<EOL>collection = cfg[AccessParams.KEY_COLLECTION]<EOL>match_params = cfg[AccessParams.KEY_MATCH_PARAMS] if AccessParams.KEY_MATCH_PARAMS in cfg else {}<EOL>if triggers_on:<EOL><INDENT>self.__exec_trigger(Trigger.ACTION_BEFORE_UPSERT, collection, input_object, match_params)<EOL><DEDENT>if cfg[AccessParams.KEY_TYPE] == AccessParams.TYPE_SINGLE:<EOL><INDENT>result =  CRUD.upsert_single(self.__db, collection, input_object, match_params)<EOL><DEDENT>elif cfg[AccessParams.KEY_TYPE] == AccessParams.TYPE_MULTI:<EOL><INDENT>result =  CRUD.upsert_multi(self.__db, collection, input_object, match_params)<EOL><DEDENT>if triggers_on:<EOL><INDENT>self.__exec_trigger(Trigger.ACTION_AFTER_UPSERT, collection, input_object, match_params)<EOL><DEDENT>return result<EOL>
Updates or inserts single document or list of documents into MongoDB collection
:param cfg:
    {
        AccessParams.KEY_COLLECTION: <Collection to update>,
        AccessParams.KEY_OBJECT: <The modifications to apply>,
        AccessParams.KEY_MATCH_PARAMS: <A query that matches the documents to update>,
        AccessParams.KEY_TYPE: <AccessParams.TYPE_SINGLE or AccessParams.TYPE_MULTI>
    }
:param triggers_on: enables/disables triggers (default - True)
:return: result of upsert operation - id or number of updated documents