Reputation: 664
I am trying to use pymongo's find_one_and_update() method to update some values in mongoDB, but I need to filter based on two different conditions, and this does not seem possible.
I tried passing in a list of filters akin to [{"name": "name"}, {"date": "date}], but this did not work.
Is there no way to filter on multiple conditions with this method? How else can I achieve this?
Thanks
Upvotes: 3
Views: 2983
Reputation: 719
Well for multiple filters,if you need all of them to be in effect, then its just a simple filter dictonary as below:
find_one({"name": "name"}, {"date": "date"})
However, if you need to have any of those multiple filters to be in effect, then you can use $or
operator
find_one({"$or":[{"name": "name"}, {"date": "date"}]})
Upvotes: 0
Reputation: 664
I figured out that the single filter argument can be a query using boolean logic. The solution was:
{"$and":[{"name": "name"}, {"date": "date"}]}
as the filter argument.
Upvotes: 3