I'm trying to upgrade Mongoid in an Rails 4.2 app from 4.x to 5.x (5.4.1) to connect to a MongoDB 2.6.
I've updated the mongoid.yml
file to match the differences of 5.x:
development:
clients:
default:
database: my_db
hosts:
- localhost:27017
options:
but now when i try to run a query, for example User.count
i get the following error:
Mongo::Error::UnsupportedFeatures (Server at (localhost:27017) reports wire version (2), but this version of the Ruby driver requires at least (6).)
The docs say that Mongoid 5.x is compatible with MongoDB 2.6, so why the error?
I have another rails app (6.x) that uses Mongoid 7.x and connects fine to the same database.
Note: Ruby 2.6
OS: MacOS
So @javiyu's answer pointed me in the right direction, MongoDB's documentation is indeed confusing, while Mongoid itself supports MongoDB 2.6, the ruby MongoDB driver dropped support of MongoDB 2.6 from version 2.16 (deprecated and fully dropped from 2.17, which was the version i was running on), so pinning the version to 2.15 did the trick:
#last version that supports mongodb 2.6
gem 'mongo', "~> 2.15.0"
#last version to support rails 4.2, above that requires at least rails 5
gem 'mongoid', "~> 5.4.0"