def upsert_single ( db , collection , object , match_params = None ) : return str ( db [ collection ] . update_one ( match_params , { "$set" : object } , upsert = True ) . upserted_id )
modify element in pymongo python
Wrapper for pymongo . update_one () : param db : db connection : param collection : collection to update : param object : the modifications to apply : param match_params : a query that matches the documents to update : return : id of updated document
def upsert_single(db, collection, object, match_params=None):
        """
        Wrapper for pymongo.update_one()
        :param db: db connection
        :param collection: collection to update
        :param object: the modifications to apply
        :param match_params: a query that matches the documents to update
        :return: id of updated document
        """
        return str(db[collection].update_one(match_params, {"$set": object}, upsert=True).upserted_id)