Install the Gem

Mongoid is bundled as a gem, and is hosted on Rubygems. It can be installed manually or with bundler.

To install the gem manually:

gem install mongoid

To install the gem with bundler, include the following in your Gemfile:

gem 'mongoid'

Using Mongoid with a New Rails Application

By using the railsmdb CLI a new Ruby on Rails application can be quickly generated using the same options as rails new, but configured to work with MongoDB:

railsmdb new my_new_rails_app

The rails CLI can also be used, however when creating a new Rails application and where Mongoid will be used for data access, provide the --skip-active-record flag to the rails new command to avoid depending on and configuring ActiveRecord.

Additional examples can be found in the tutorials.

Using Mongoid with an Existing Rails Application

Using the railsmdb CLI an existing Rails application can easily be configured for use with Mongoid:

railsmdb setup

Converting an existing Rails application without using railsmdb can be done by updating the config/application.rb file to remove the require 'rails/all' line and explicitly include the required frameworks (which could be all of the frameworks provided by Rails with the exception ofActiveRecord). Any references to ActiveRecord in files in the config directory and in the models also need to be removed.