Applying case Insensitive filter while using pymongo's update_many

64 views Asked by At

Can someone suggest how to update multiple documents while using regex in filter query of update_many? Here is my query:

db['collection'].update_many({"col1":{ "$regex" : "NO" , "$options" : "i"}},{"$set":{"col2":"NO"}})
1

There are 1 answers

0
HobbyCoder On

Here is a quick fix that I used:

no_regex = ['no','No','NO']
db['collection'].update_many({"col1":{ "$in" : no_regex}},{"$set":{"col2":"NO"}})