Installation¶
On this page
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:
To install the gem with bundler, include the following in your Gemfile
:
Using Mongoid with a New Rails Application¶
When creating a new Rails application and wish to use Mongoid for
data access, give the --skip-active-record
flag to the rails new
command to avoid depending on and configuring ActiveRecord..
Using Mongoid with an Existing Rails Application¶
When converting an existing Rails application to use Mongoid for data access,
the config/application.rb
file needs to be updated 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 of
ActiveRecord). Any references to ActiveRecord in files in the config
directory and in the models also need to be removed.
Ruby MongoDB Driver Compatibility¶
The following compatibility table specifies the versions of Ruby driver for
MongoDB
(the mongo
gem) supported by the most recent patch releases of the
specified Mongoid versions.
Note
Older versions of Mongoid within the same minor release may support older driver versions. For example, Mongoid 7.0.5 supports driver versions 2.5 and newer, whereas Mongoid 7.0.6 requires driver version 2.7 or newer.
Mongoid | Driver 2.11 | Driver 2.10 | Driver 2.9 | Driver 2.8 | Driver 2.7 |
---|---|---|---|---|---|
7.0 | ✓ | ✓ | ✓ | ✓ | ✓ |
6.4 | ✓ | ✓ | ✓ | ✓ | ✓ |
Ruby Compatibility¶
The following compatibility table specifies the versions of Ruby interpreters supported by Mongoid.
Mongoid | Ruby 2.7 | Ruby 2.6 | Ruby 2.5 | Ruby 2.4 | Ruby 2.3 | Ruby 2.2 | JRuby 9.2 | JRuby 9.1 |
---|---|---|---|---|---|---|---|---|
7.0 | ✓ | ✓ | ✓ | ✓ [1] | ✓ | ✓ [2] | ✓ | ✓ |
6.4 | ✓ | ✓ | ✓ [1] | ✓ | ✓ [2] | ✓ | ✓ |
[1] | (1, 2) Ruby version 2.4.1 or higher is required. |
[2] | (1, 2) Ruby version 2.2.2 or higher is required. |
MongoDB Compatibility¶
The following compatibility table specifies the recommended version(s) of Mongoid for use with a specific version of MongoDB.
Note that in order to use features of a particular MongoDB server version, both the driver and Mongoid must support that server version. Please refer to the driver compatibility page for driver compatibility matrices.
Mongoid | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 2.6 |
---|---|---|---|---|---|---|---|
7.0 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
6.4 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Rails Compatibility¶
The following compatibility table specifies which versions of Rails are supported by Mongoid.
Mongoid | Rails 6.1 | Rails 6.0 | Rails 5.2 | Rails 5.1 | Rails 5.0 | Rails 4.2 |
---|---|---|---|---|---|---|
7.0 | ✓ [4] | ✓ [3] | ✓ | ✓ | ||
6.4 | ✓ | ✓ | ||||
6.3 | ✓ | ✓ | ||||
6.2 | ✓ | ✓ | ||||
6.1 | ✓ | |||||
6.0 | ✓ | |||||
5.4 | ✓ | |||||
5.2 | ✓ |
[3] | Rails 6.0 requires Mongoid 7.0.5 or later. |
[4] | Rails 6.1 requires Mongoid 7.0.12 or later. |