我需要一个mongoid搜索,比如带有整数列的查询。例如:
SELECT * FROM users WHERE mobile LIKE '%9980%';这是我的模型:
class User
include Mongoid::Document
include Mongoid::Timestamps
##
# Columns
field :name, type: String
field :mobile, type: Integer
end我已经试过了以下例子。但没有运气:
User.where(:$where => "/^#{params[:mobile]}/")
User.any_of({mobile: /.*#{params[:mobile]}.*/i})
User.where(mobile: /8801/))怎么用蒙古文写?
发布于 2014-09-09 08:59:52
尝尝这个
User.where(mobile: /.*#{params[:mobile]}.*/i)发布于 2014-09-09 09:22:59
解决方案:
users = User.where(:$where => "/^#{params[:mobile]}/.test(this.mobile)")发布于 2014-09-09 08:33:36
User.where(:mobile => /\d*{params[:mobile]}\d*/)
蒙哥德的类似函数只不过是where对regexp的争论
https://stackoverflow.com/questions/25739745
复制相似问题