1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【備忘録】MongoDB使用してRailsでマイグレする方法

Last updated at Posted at 2018-12-09

MongoDBのフィールドを追加等したときの
Rails側のマイグレーション方法の備忘録。
(コマンド叩く必要ないので)

例:
MongoDBの
コレクション:Userに
フィールド:emailを追加

環境

Rails v5.2.1
MongoDB v4.0.2

Rails

model側に

user.rb
class User
  include Mongoid::Document
  include Mongoid::Timestamps
  field :name, type: String
  # (追加)emailフィールド
  field :email, type: String

  validates :name,{presence: true, uniqueness: true}
  
  # (追加)emailカラムに関するバリデーション
  validates :email,{presence: true, uniqueness: true}

end

的な感じでフィールド追加すればいける

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?