Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Given that I have a string such as

"Donald Trump <donald@trump.com>" 
"Art Job <art@job.com>"

How can I find every row that contains "donald@trump.com" using MongoDB in Rails?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
310 views
Welcome To Ask or Share your Answers For Others

1 Answer

From the documentation:

search_string = params['search']

# Constructor syntax coll.find({"name" => Regexp.new(search_string)})

# Literal syntax coll.find({"name" => /#{search_string}/})

Beware though... You can't use an index with this query since your regex isn't anchored to the front of the string.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...