开发者

Ruby Mongo mapper contains "abc"?

开发者 https://www.devze.com 2023-03-02 23:58 出处:网络
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?

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

精彩评论

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