If one mistakenly specifies read preference as a symbol in Mongoid, as follows:
development:
clients:
default:
database: mongoid
hosts:
- localhost:27100
options:
read: :primary
Instead of the correct specification which uses a hash with mode subkey, as follows:
development:
clients:
default:
database: mongoid
hosts:
- localhost:27100
options:
read:
mode: :primary
The driver produces an error as follows:
Mongo::Error::InvalidReadOption (Invalid read option: primary: must be a hash)
The driver can in addition suggest a fix which is to replace the primitive value (:primary) with a hash (
{mode: :primary}).
Test apps: https://github.com/p-mongo/tests/tree/master/mongoid-spec-rp-symbol & https://github.com/p-mongo/tests/tree/master/mongoid-spec-rp-hash.
Original report:
Here is a coding error. It is not related to the database, seem to be a driver only error.
My server environment works but my RSpec tests don't work.
- See backtrace.png for the error. It's all about the mongo and mongoid gems. I tried with mongoid 6.1.1, 6.2.1 and 6.4.2. Although the error message is a bit different with 6.1.1.
- See init.png. The initialization is correct, at least that part the :read value which is a hash.
- Since 6.0.0, the read mode ("primary") is taken out of the hash. See read_mode.png
- Finally, the options :read value is no longer a hash (of course, it was taken out of it in step 3). This causes the exception we see in step 3. The validate call errors out.
- is duplicated by
-
RUBY-1590 Code error
- Closed
- related to
-
MONGOID-4564 Test suite broken due to invalid read preference being passed to driver
- Closed