mongodb and mogoid in rails 4

Install Mongodb On Ubuntu

Install Mogoid gem in rails 4:
In Gem file:

gem 'mongoid', github: 'mongoid/mongoid'
gem 'bson_ext'

Run this command:

bundle update

To generate mongoid.yml file

rails g mongoid:config

Detailed reference

Rails Cast

Replacing Active Record in rails app:

Remove/comment out you sql gem from gem file for instance sqlite3, mysql, pgsql.

#gem 'sqlite3'

In “app/config/mongoid.yml” comment out this line

# consistency: :eventual

and replace with this line

consistency: :strong

In config/application.rb comment out this line

# require 'rails/all'

and add these lines

require "action_controller/railtie"
require "action_mailer/railtie"
#require "active_resource/railtie" #uncomment if you want to use active_resource
require "sprockets/railtie"

In config/environments/development.rb comment out this line, as it was used by active record not in mongoid

# config.active_record.migration_error = :page_load

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: , , , , ,
Posted in mongodb

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: