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:
This will work:
- Create a new MongoClient instance by connecting to node specifying readPreference=secondary in the connection string, e.g.:
- Print the value of client.readPreference.mode.
The value is secondary.
The value is primary.