您好我想使用Ruby on Rails
版本5与mongodb
我使用mongoid
class SkillSet
include Mongoid::Document
field :name, type: String # this field has to be unique
def some_method
end
end
答案 0 :(得分:2)
您需要在该字段下创建索引mongoid-index,这是更新后的代码
class SkillSet
include Mongoid::Document
field :name, type: String
index({ name: 1 }, { unique: true, name: "name_index" })
def some_method
end
end
运行此rake db:mongoid:create_indexes
以在mongodb中创建索引