[pymongo] Find every document that contains an element of my array

HI! I’m trying to find an elements on my database that has a value equal to any element of my array.
For example, I have the array [“red”,“brown”] in my code.
I want to search on the database any document that has the “color” value equal to any element of my array, so red or brown. But I’ve not found anything useful on MongoDB docs or on internet,
In my head sound like:

myCuster.myDB.find({"color": myArray}) But didn’t work


myCuster.myDB.find( { "color" : { "$in" : myArray } } )

Please make sure you know why it works by visiting https://docs.mongodb.com/manual/reference/operator/query/in/.

1 Like

And if I may add, experiment with { color : myArray }. Create a documents with the following

d1 = { color : [ "red" , "brown" ] }
d2 = { color : [ "brown" , "red" ] }
d3 = { color : [ "red" , "brown" , "blue" ] }

to see which document will match

myCuster.myDB.find({"color": myArray})