3

I have a document in Mongo with two array fields:

field   :app_usernames,     type:  Array 
field   :email_addresses,   type:  Array

I'd like to create a function which take an array of usernames and an array of email addresses to search collection. The kicker is that I want it to return documents which have any of the values passed in the arrays:

def find_people(usernames_to_search, emails_to_search)...

So given a document with field values:

app_usernames = ['test1','test2','test3']
email_addresses = ['test1@test.com','test2@test.com']

I want the function to find it when any of those values are searched, via the array parameters. It should return this document in the following cases:

find_people nil,['test1@test.com']
find_people ['test3'],['test1@test.com']
find_people ['oldusername'],['test1@test.com']

The last one seems to be causing me trouble.

Thus far I've tried

.or(:app_usernames.in usernames_to_search, :email_addresses.in emails_to_search)

But to no avail.

4

1 に答える 1