@@ -20,13 +20,6 @@ const {
2020
2121const debug = require ( 'debug' ) ( 'mongodb-data-service:instance-detail-helper' ) ;
2222
23- function getReadPreferenceOptions ( db ) {
24- // `db.command` does not use the read preference set on the
25- // connection, so here we explicitly to specify it in the options.
26- const readPreference = db . s ? db . s . readPreference : ReadPreference . PRIMARY ;
27- return { readPreference } ;
28- }
29-
3023/**
3124 * aggregates stats across all found databases
3225 * @param {Object } results async.auto results
@@ -85,7 +78,7 @@ function getBuildInfo(results, done) {
8578 } ;
8679
8780 const adminDb = db . databaseName === 'admin' ? db : db . admin ( ) ;
88- adminDb . command ( spec , getReadPreferenceOptions ( db ) , function ( err , res ) {
81+ adminDb . command ( spec , { } , function ( err , res ) {
8982 if ( err ) {
9083 // buildInfo doesn't require any privileges to run, so if it fails,
9184 // something really went wrong and we should return the error.
@@ -105,7 +98,7 @@ function getCmdLineOpts(results, done) {
10598 } ;
10699
107100 const adminDb = db . databaseName === 'admin' ? db : db . admin ( ) ;
108- adminDb . command ( spec , getReadPreferenceOptions ( db ) , function ( err , res ) {
101+ adminDb . command ( spec , { } , function ( err , res ) {
109102 if ( err ) {
110103 debug ( 'getCmdLineOpts failed!' , err ) ;
111104 return done ( null , { errmsg : err . message } ) ;
@@ -220,7 +213,7 @@ function getHostInfo(results, done) {
220213 } ;
221214
222215 const adminDb = db . databaseName === 'admin' ? db : db . admin ( ) ;
223- adminDb . command ( spec , getReadPreferenceOptions ( db ) , function ( err , res ) {
216+ adminDb . command ( spec , { } , function ( err , res ) {
224217 if ( err ) {
225218 if ( isNotAuthorized ( err ) ) {
226219 // if the error is that the user is not authorized, silently ignore it
@@ -260,14 +253,12 @@ function listDatabases(results, done) {
260253 listDatabases : 1
261254 } ;
262255
263- const options = getReadPreferenceOptions ( db ) ;
264-
265256 const adminDb = db . databaseName === 'admin' ? db : db . admin ( ) ;
266- adminDb . command ( spec , options , function ( err , res ) {
257+ adminDb . command ( spec , { } , function ( err , res ) {
267258 if ( err ) {
268259 if ( isNotAuthorized ( err ) ) {
269260 // eslint-disable-next-line no-shadow
270- adminDb . command ( { connectionStatus : 1 , showPrivileges : 1 } , options , function ( err , res ) {
261+ adminDb . command ( { connectionStatus : 1 , showPrivileges : 1 } , { } , function ( err , res ) {
271262 if ( err ) {
272263 done ( err ) ;
273264 return ;
@@ -352,7 +343,7 @@ function getDatabase(client, db, name, done) {
352343 dbStats : 1
353344 } ;
354345
355- const options = getReadPreferenceOptions ( db ) ;
346+ const options = { } ;
356347 debug ( 'running dbStats for `%s`...' , name ) ;
357348 client . db ( name ) . command ( spec , options , function ( err , res ) {
358349 if ( err ) {
@@ -385,15 +376,8 @@ function getDatabases(results, done) {
385376function getUserInfo ( results , done ) {
386377 const db = results . db ;
387378
388- const options = getReadPreferenceOptions ( db ) ;
389-
390379 // get the user privileges
391- db . command ( {
392- connectionStatus : 1 ,
393- showPrivileges : true
394- } ,
395- options ,
396- function (
380+ db . command ( { connectionStatus : 1 , showPrivileges : true } , { } , function (
397381 err ,
398382 res
399383 ) {
@@ -410,7 +394,7 @@ function getUserInfo(results, done) {
410394 }
411395 const user = res . authInfo . authenticatedUsers [ 0 ] ;
412396
413- db . command ( { usersInfo : user , showPrivileges : true } , options , function (
397+ db . command ( { usersInfo : user , showPrivileges : true } , { } , function (
414398 _err ,
415399 _res
416400 ) {
@@ -507,7 +491,15 @@ function getDatabaseCollections(db, done) {
507491
508492 const spec = { } ;
509493
510- db . listCollections ( spec , getReadPreferenceOptions ( db ) ) . toArray ( function ( err , res ) {
494+ /**
495+ * @note : Durran: For some reason the listCollections call does not take into
496+ * account the read preference that was set on the db instance - it only looks
497+ * in the passed options: https://github.com/mongodb/node-mongodb-native/blob/2.2/lib/db.js#L671
498+ */
499+ const rp = db . s ? db . s . readPreference : ReadPreference . PRIMARY ;
500+ const options = { readPreference : rp } ;
501+
502+ db . listCollections ( spec , options ) . toArray ( function ( err , res ) {
511503 if ( err ) {
512504 if ( isNotAuthorized ( err ) || isMongosLocalException ( err ) ) {
513505 // if the error is that the user is not authorized, silently ignore it
0 commit comments