خرید بک لینک

Vote count: 0

i have a python def which has a mandatory parameter and some optional params. I want to take all the non-zero optional params passed to that def and update them in the mongoDB.

Currently I'm using something like this:

def updateTable(mandVar, varA=0, varB=0, varC=0):
    #check the values of varA, varB, varC which are non-zero, and update only those in the table
    if varA:
            db.tableRouter.update_one(
                    {"mand_var":mandVar},
                    {
                            "$set":{
                                    "var_a":varA
                            }
            })
    if varB:
            db.tableRouter.update_one(
                    {"mand_var":mandVar},
                    {
                            "$set": {
                                    "var_b":varB
                            }
            })
    if varC:
            db.tableRouter.update_one(
                    {"mand_var":mandVar},
                    {
                            "$set": {
                                    "var_c":varC
                            }
            })

    myCur = db.tableRouter.find({"mand_var":mandVar})
    for cur in myCur:
            retu cur

This doesn't look very good. Is there a way where I can update all the params at once? Also, in this case, if I need to call this def and have only some of the optional params I'll need to have some empty params like this:

ret = updateTable(mand_arg,"",opt_argB,opt_argC)

Is there any other way to do this?

asked 4 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 27 خرداد 1395 ساعت: 22:07

صفحه بندی