pymongo: arrayFilters & update_one() got multiple values for argument 'upsert'

1,070 views
Skip to first unread message

Cenk

unread,
Apr 23, 2018, 7:52:05 PM4/23/18
to mongodb-user
I am getting the following error for:


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


I am guessing that arrayFilters have not been implemented in pymongo yet. 

Can anyone confirm this or give me a hand for a workaround? I need to find and update the array element by child_id, adding a new prop to it.
 

            update_id = db.Accounts.update_one(
                {"_id": my_id }, 
                {
                    "$set": {
                        "children.$[element].decimals": decimals_value,
                    },
                },
                {
                    "arrayFilters": [
                        {
                            "element._id": child_id
                        }
                    ]
                },                
                upsert=True)     


Thanks,

Cenk 

Bernie Hackett

unread,
Apr 24, 2018, 11:15:17 AM4/24/18
to mongodb-user
Array filters support was added in PyMongo 3.6. See the documentation here:

Tony

unread,
Sep 27, 2018, 6:40:06 AM9/27/18
to mongodb-user
Hey I am getting same error TypeError: update() got multiple values for keyword argument 'upsert'.

I am using python version : 2.7.15+ [GCC 8.2.0] & pymongo version : 3.7.1 & OS: 4.18.0-kali1-amd64

i wanted to update sub-document in nested array using arrayfilters 

this is my document for example,
{
  "_id": {
      "$oid": "5bac8c2bfb6fc01d131ae881"
  },
  "a": [
      {
          "b": 0,
          "c": [
              {
                  "d": 0
              },
              {
                  "d": 1
              }
          ]
      },
      {
          "b": 1,
          "c": [
              {
                  "d": 0
              },
              {
                  "d": 1
              }
          ]
      }
  ]
}


 and i am doing update using following query


coll.update({}, {'$set': {'a.$[i].c.$[j].d': 2}}, {'$arrayFilters': [{'i.b': 0}, {'j.d': 0}]},upsert=False)

which gave me error : TypeError: update() got multiple values for keyword argument 'upsert'.

Bernie Hackett

unread,
Sep 27, 2018, 7:18:45 PM9/27/18
to mongodb-user
The third parameter to update() is "upsert". You are passing a python dict to the upsert positional parameter, then passing upsert again as a keyword argument.


You can pass the arrayFilters parameter as a keyword argument instead. PyMongo also supports an explicit array_filters parameter in the update_one and update_many methods:


Please note that the update() method is deprecated. Use update_one or update_many instead.
Reply all
Reply to author
Forward
0 new messages