开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜