Given a collection users, with:
{ "firstName" : "raymond", "lastName" : "Barlow" }
This works as expected (found):
> db.users.find({"firstName":{$regex:".*ray.*"}})
{ "firstName" : "raymond", "lastName" : "Barlow" }
As does this (not found):
> db.users.find({"lastName":{$regex:".*ray.*"}})
>
But, this does not work as I would have expected:
> db.users.find({$or:[{"firstName":{$regex:".*ray.*"}},{"lastName":{$regex:".*ray.*"}}]})
>
Certainly, it should have matched the email regex?
Basically, I'm trying to implement a search function that works over a number of fields. On the front end, the user searches for any partial string, and it gets matched to a number of different fields in the user object. Is there a better way to achieve this?
I am using version 2.0.1.
Help/advice appreciated!
Regards,
Raymond Barlow