MongoDB 如何把 正则表达式 存储到 mongodb 里面 (mongoid)

sitoto · 2013年07月19日 · 最后由 luikore 回复于 2013年07月19日 · 4150 次阅读

Mongoid 的 里面有 Regexp 的 类型

我定义如下

field :name_reg, :type => Regexp

运行却报错,请教一下,如何把 正则表达式存储到 mongodb 里面 ××××××××××××××× Routing Error

undefined method `instantiate' for Regexp:Class Try running rake routes for more information on available routes. ×××××××××××××××××

Below is a list of valid types for fields.

Array BigDecimal Boolean Date DateTime Float Hash Integer Moped::BSON::ObjectId Moped::BSON::Binary Range Regexp String Symbol Time TimeWithZone

Routing Error 奇怪

字符串不行么。。

比如说我要存储这个: /\d+/ 如果存为字符串格式就变成: "/\\d+\\//" 存字符串还是不合适

用 to_s 就行了,然后用 Regexp.new 就可以回来了

Regexp.new /d+/i.to_s

那个 regexp 类型是 js 的,很多事情都做不来,不如存字符串

需要 登录 后方可回复, 如果你还没有账号请 注册新账号