Reputation: 23767
Instead of saying:
@b = coll.find("xpto.it" => @email)
if it's equal to @email
, how can I look if it contains the string @email
?
EDIT
It doesn't work when there's something like:
"Donald Trump <[email protected]>"
Upvotes: 2
Views: 973
Reputation: 18046
You can also construct a regular expression dynamically. To match a given search string:
search_string = @email
# Constructor syntax
coll.find({"name" => Regexp.new(search_string)})
# Literal syntax
coll.find({"name" => /#{search_string}/})
Reference:
http://api.mongodb.org/ruby/current/file.TUTORIAL.html
Upvotes: 1