How to check if an Mongoid array field contains one or more items in another array?

If the field is an integer, then the following works:

User.where(id: [1,3,5])    

But what if the field is an array? For example, the user has a field which is an array of favorite_numbers:

How to find users that have a favorite_number of 1, 3 or 5?

Rails 4.1.7
Mongoid 5.0.0

Edit: Added Mongoid.

Read more here:

Content Attribution

This content was originally published by B Seven at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: