TypeError: update_one() got multiple values for argument 'upsert'

Viewed 1293
testdb.update_one({'id': id}, {"$set": {'testArrayLevel1.$[i].testArrayLevel2.$[j].status':"registered"}},{"array_filters":[{"i.user_id":user_id}, {"j.user_type": user_type}]}, upsert=False)

Getting TypeError:

update() got multiple values for argument 'upsert'. If removed upsert=False, then getting:
TypeError: upsert must be True or False

What is the correct way to do this python code calling pymongo? Any inputs will be of great help.

4 Answers

The problem in the way you pass args to function, the value_args is malformed, so instead of

testdb.update_one({'id': id}, {"$set": {'testArrayLevel1.$[i].testArrayLevel2.$[j].status':"registered"}},{"array_filters":[{"i.user_id":user_id}, {"j.user_type": user_type}]}, upsert=False)

Use right passing for value_args, also formatting will make your life eathier:

testdb.update_one({'id': id},
                  {
                      "$set": {'testArrayLevel1.$[i].testArrayLevel2.$[j].status':"registered"},
                      "array_filters":[{"i.user_id":user_id}, {"j.user_type": user_type}]
                  },
                  upsert=False)

NOTE By default upsert is set to false, so may want to consider removing it, as I believe you used same call and the upsert were set to dict, which won't be the case after fixing arguments.

The right usage is here ( got the right comamnd after posting another question):

mongo.db.testdb.update_one({'id': id},
{"$set": {'testArrayLevel1.$[i].testArrayLevel2.$[j].status': "registered"}},
array_filters=[{"i.user_name": user_name}, {"j.user_type": user_type}],
upsert=False)

try just with "update" not "update_one".

testdb.update({'id': id}, {"$set": {'testArrayLevel1.$[i].testArrayLevel2.$[j].status':"registered"}},{"array_filters":[{"i.user_id":user_id}, {"j.user_type": user_type}]}, upsert=False)

you can done this type data is:

{
    "_id" : 1,
    "user" : "usr_name",
    "tasks_list" : [
        {
            "task_id" : "dc12210e-5bc9-41c1-af55-adcdec09de8c",
            "status" : "running",
            "info" : "extract_group"
        }
    ]
}

solution:

tasks.update_one(filter={"user":usr},
                 update={"$set":{"tasks_list.$[elem].status":"complite"}},
                 upsert=False,array_filters=[{"elem.task_id":task_id}])
Related