MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Use LIKE/regex com variável em mongoid

searchterm = (params[:searchlogparams][:searchterm])
@tweets = Tweet.any_of({ :text => Regexp.new ("/.*"+searchterm+".*/") })

ou
searchterm = (params[:searchlogparams][:searchterm])
@tweets = Tweet.any_of({ :text => /.*#{searchterm}.*/ })