def upsert(self, cfg, triggers_on=True):
        """
        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
        """
        input_object = cfg[AccessParams.KEY_OBJECT]
        collection = cfg[AccessParams.KEY_COLLECTION]
        match_params = cfg[AccessParams.KEY_MATCH_PARAMS] if AccessParams.KEY_MATCH_PARAMS in cfg else {}
        if triggers_on:
            self.__exec_trigger(Trigger.ACTION_BEFORE_UPSERT, collection, input_object, match_params)
        if cfg[AccessParams.KEY_TYPE] == AccessParams.TYPE_SINGLE:
            result =  CRUD.upsert_single(self.__db, collection, input_object, match_params)
        elif cfg[AccessParams.KEY_TYPE] == AccessParams.TYPE_MULTI:
            result =  CRUD.upsert_multi(self.__db, collection, input_object, match_params)
        if triggers_on:
            self.__exec_trigger(Trigger.ACTION_AFTER_UPSERT, collection, input_object, match_params)
        return result
def upsert ( self , cfg , triggers_on = True ) : input_object = cfg [ AccessParams . KEY_OBJECT ] collection = cfg [ AccessParams . KEY_COLLECTION ] match_params = cfg [ AccessParams . KEY_MATCH_PARAMS ] if AccessParams . KEY_MATCH_PARAMS in cfg else { } if triggers_on : self . __exec_trigger ( Trigger . ACTION_BEFORE_UPSERT , collection , input_object , match_params ) if cfg [ AccessParams . KEY_TYPE ] == AccessParams . TYPE_SINGLE : result = CRUD . upsert_single ( self . __db , collection , input_object , match_params ) elif cfg [ AccessParams . KEY_TYPE ] == AccessParams . TYPE_MULTI : result = CRUD . upsert_multi ( self . __db , collection , input_object , match_params ) if triggers_on : self . __exec_trigger ( Trigger . ACTION_AFTER_UPSERT , collection , input_object , match_params ) return result
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