Ruby Mongo mapper contains "abc"?
Instead of saying:
@b = coll.find("xpto.it" => @e开发者_开发技巧mail)
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 <donal@tr.com>"
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
精彩评论