This PR updates our use of the db.command function which is one of those operations with the aspect WRITE_OPERATION to explicitly pass the readPreference which the user set up in Compass. This makes it so we have the same behavior as before and previous direct connections to secondaries don't suddenly stop working.
I think we could do a lot of cleanup here. I'm also not quite sure why we're using db.command for listing databases instead of db.listDatabases. This should fix the issue though. We also shouldn't be reaching into db.s.readPreference. I can create a tech debt ticket 🤔
I'm not sure if anywhere else in our codebase we rely on db.command follow the readPreference of the connection, so I'm looking into that.
Connecting and looking at data in a secondary with a direct connection:
This PR is https://github.com/mongodb-js/data-service/pull/282 just without the many package-lock.json changes, since those probably have some unintended consequences in Compass.
Here's the copy pasted description from that one.
In 3.6.3 the driver updated how operations are run so that operations which have the aspect
WRITE_OPERATION
default to primary instead of using the connection's readPreference: https://github.com/mongodb/node-mongodb-native/commit/ddcd03d0f934d11a0707dd7d89bc4cb165775f55This PR updates our use of the
db.command
function which is one of those operations with the aspectWRITE_OPERATION
to explicitly pass the readPreference which the user set up in Compass. This makes it so we have the same behavior as before and previous direct connections to secondaries don't suddenly stop working.I think we could do a lot of cleanup here. I'm also not quite sure why we're using
db.command
for listing databases instead ofdb.listDatabases
. This should fix the issue though. We also shouldn't be reaching intodb.s.readPreference
. I can create a tech debt ticket 🤔I'm not sure if anywhere else in our codebase we rely on
db.command
follow the readPreference of the connection, so I'm looking into that.Connecting and looking at data in a secondary with a direct connection: