【发布时间】:2019-12-02 12:59:17
【问题描述】:
我有一个 API 模式并使用 Mongoid 的 Ruby On Rails 应用程序。 这是我的模型:
class Posts
include Mongoid::Document
field :title , type: String
field :created_at , type: Time , default: Time.now
end
现在一段时间后,在 Post 集合中有很多记录,从现在开始我需要在模型中添加一个字段 "body",如下所示:
class Posts
include Mongoid::Document
field :title , type: String
field :body , type: String
field :created_at , type: Time , default: Time.now
end
问题是,应用程序仍然不理解这个变化!我没有使用 Rails 的内置 SQL 数据库,并且我的应用程序中没有 "db" 文件夹,因为它的 API 模式和使用 Mongoid。所以我不能使用命令rails db:migrate
那么如何在 Rails 应用中更新 Mongoid 模型呢?
还有一个问题是我怎样才能无模式地使用它?我只是定义模型的名称而不定义任何字段。并且添加功能,只需传递新记录的 JSON 对象并将其作为无模式模型使用。
【问题讨论】:
标签: ruby-on-rails schema mongoid