-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 3.6.3, 4.0.0
-
Component/s: Shell
-
None
Problem Description
It seems the driver is not handling readPreference as expected when specified in the connection string.
This affects both the current 3.6.3 release as well as the current 4.0.0 beta version.
After some input by Matt it turns out this is not a duplicate of NODE-2807. The fix in NODE-2807 fixed it when being passed directly as an additional parameter when creating the MongoClient. However, when using only the connection string, the readPreference is not parsed.
In short this does not work:
const client = await MongoClient.connect( 'mongodb://root:password123@localhost:28001/?directConnection=true&readPreference=secondary' );
This will work:
const client = await MongoClient.connect( 'mongodb://root:password123@localhost:28001/?directConnection=true', { readPreference: 'secondary' } );
Steps to Reproduce
- Create a new MongoClient instance by connecting to node specifying readPreference=secondary in the connection string, e.g.:
mongodb://root:password@localhost:28001/?readPreference=secondary&directConnection=true - Print the value of client.readPreference.mode.
Expected Results
The value is secondary.
Actual Results
The value is primary.