I have a collection like this:
user_id albums
1 [1 2 3 4]
2 [3 5 7 8]
I want to find out all the records that, the albums contains 3 or 7 or 8, I wrote the code like this but not working:
or_array = []
or_array.append({"albums":3})
or_array.append({"albums":7})
or_array.append({"albums":8})
collection1.find({"$or":or_array})
What is the right way to do this?
try this
from the mongodb docs,
[IN] allow[s] you to specify an array of possible matchesIf that doesn’t work, maybe back track and look at the actual types of
37and8in the collection to ensure they are ints.