-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Explicitly pass read preference with db.command commands COMPASS-4539 #282
fix: Explicitly pass read preference with db.command commands COMPASS-4539 #282
Conversation
|
|
||
| const debug = require('debug')('mongodb-data-service:instance-detail-helper'); | ||
|
|
||
| function getReadPreferenceOptions(db) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't db.s.readPreference a private method in the driver?
Also .. I think here we can just hardcode ReadPreference.PRIMARY_PREFERRED, i see no harm, may be missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, wrote this quick using a bit of what we already had https://github.com/mongodb-js/data-service/blob/master/lib/instance-detail-helper.js#L500 , I'll see if there's a public method we can use. Looks like we don't pass our connection model through these instance detail helpers.
| this.database.admin().command({ | ||
| listDatabases: 1 | ||
| }, { | ||
| readPreference: this.model.readPreference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also depends on how is used, if is only used by compass for building the UI i'd go with primary preferred always, what would be the consequence of listing dbs from a secondary?
…OMPASS-4539 (#282)" This reverts commit f2bd36d.
…OMPASS-4539 (#282)" (#283) This reverts commit f2bd36d.
In 3.6.3 the driver updated how operations are run so that operations which have the aspect
WRITE_OPERATIONdefault to primary instead of using the connection's readPreference:mongodb/node-mongodb-native@ddcd03d
This PR updates our use of the
db.commandfunction which is one of those operations with the aspectWRITE_OPERATIONto 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.commandfor 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.commandfollow the readPreference of the connection, so I'm looking into that.Connecting and looking at data in a secondary with a direct connection:
