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

sitoto · July 19, 2013 · Last by luikore replied at July 19, 2013 · 4150 hits

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+\\//" 存字符串还是不合适

#3 楼 @sitoto base64 后再存

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

Regexp.new /d+/i.to_s

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

You need to Sign in before reply, if you don't have an account, please Sign up first.