1
votes

I am trying to run a python code to update a collection with arrays. The below statement give error wtih pymongo . Please guide

db.students.update({}, {'$set': {"grades.$[element]": 100}}, {'multi': true, 'arrayFilters': [{"element": { '$gte': 100}}]} )

tried : multi=True tried : multi:True

I am getting the below error : common.validate_boolean("upsert", upsert) File "F:\Program Files\Python3.7\lib\site-packages\pymongo\common.py", line 159, in validate_boolean raise TypeError("%s must be True or False" % (option,))

TypeError: upsert must be True or False
1

1 Answers

0
votes

Pymongo's syntax is a tad different than Mongo's syntax, you should write it like this:

db.students.update({}, {'$set': {"grades.$[element]": 100}}, multi=True, array_filters=[{"element": {'$gte': 100}}])

Also update is deprecated, and in your case you should use update_many instead.

db.students.update_many({}, {'$set': {"grades.$[element]": 100}}, array_filters=[{"element": {'$gte': 100}}])