Reputation: 11
In ruby on rails normally use SQLite as a database.so a special property of rails called migration are work.but when we use "mongodb" as a database in rails.I see there have no migrate folder in the db directory. Is there any way to use this migration property in rails when use mongodb.
Upvotes: 1
Views: 1920
Reputation: 3085
According to the documentation here, db:migrate:
Exists only for dependency purposes, but does not actually do anything.
However, because I am not sure of what version of rails you're using, how your project was setup and if you intend using just mongodb
I will describe the process for both possibilities from scratch with all assumptions if any clearly stated.
This approach assumes you want to use mongodb
alone
--skip-active-record
switch.sqlite3
from your Gemfile
gem 'mongoid'
to your Gemfile
bundle
rails g mongoid:config
application.rb
file and make sure that inside the 'class Application' you have this line Mongoid.load! './config/mongoid.yml'
It's sometimes not included when the config is generated, but is needed to use Mongoid
.Mongoid
is ready to go. The Rails generators for model
, scaffold
, etc have been overridden by Mongoid
. Any models, scaffolds etc that you create will create classes that include the Mongoid::Document module instead of inheriting from ApplicationRecord in the models folder.
For instance, when you run
rails g model person first_name last_name email_address
if you open up the file app/models/person.rb
You'd see
class Person
include Mongoid::Document
field :first_name, type: String
field :last_name, type: String
field :email_address, type: String
end
Upvotes: 1