File tree Expand file tree Collapse file tree 2 files changed +32
-22
lines changed Expand file tree Collapse file tree 2 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -61,27 +61,29 @@ class Monitor extends EventEmitter {
61
61
62
62
// TODO: refactor this to pull it directly from the pool, requires new ConnectionPool integration
63
63
const addressParts = server . description . address . split ( ':' ) ;
64
- this . connectOptions = Object . freeze (
65
- Object . assign (
66
- {
67
- id : '<monitor>' ,
68
- host : addressParts [ 0 ] ,
69
- port : parseInt ( addressParts [ 1 ] , 10 ) ,
70
- bson : server . s . bson ,
71
- connectionType : Connection
72
- } ,
73
- server . s . options ,
74
- this . options ,
75
-
76
- // force BSON serialization options
77
- {
78
- raw : false ,
79
- promoteLongs : true ,
80
- promoteValues : true ,
81
- promoteBuffers : true
82
- }
83
- )
64
+ const connectOptions = Object . assign (
65
+ {
66
+ id : '<monitor>' ,
67
+ host : addressParts [ 0 ] ,
68
+ port : parseInt ( addressParts [ 1 ] , 10 ) ,
69
+ bson : server . s . bson ,
70
+ connectionType : Connection
71
+ } ,
72
+ server . s . options ,
73
+ this . options ,
74
+
75
+ // force BSON serialization options
76
+ {
77
+ raw : false ,
78
+ promoteLongs : true ,
79
+ promoteValues : true ,
80
+ promoteBuffers : true
81
+ }
84
82
) ;
83
+
84
+ // ensure no authentication is used for monitoring
85
+ delete connectOptions . credentials ;
86
+ this . connectOptions = Object . freeze ( connectOptions ) ;
85
87
}
86
88
87
89
connect ( ) {
Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ class Topology extends EventEmitter {
276
276
277
277
translateReadPreference ( options ) ;
278
278
const readPreference = options . readPreference || ReadPreference . primary ;
279
- this . selectServer ( readPreferenceServerSelector ( readPreference ) , options , err => {
279
+ const connectHandler = err => {
280
280
if ( err ) {
281
281
this . close ( ) ;
282
282
@@ -294,7 +294,15 @@ class Topology extends EventEmitter {
294
294
this . emit ( 'connect' , this ) ;
295
295
296
296
if ( typeof callback === 'function' ) callback ( err , this ) ;
297
- } ) ;
297
+ } ;
298
+
299
+ // TODO: NODE-2471
300
+ if ( this . s . credentials ) {
301
+ this . command ( 'admin.$cmd' , { ping : 1 } , { readPreference } , connectHandler ) ;
302
+ return ;
303
+ }
304
+
305
+ this . selectServer ( readPreferenceServerSelector ( readPreference ) , options , connectHandler ) ;
298
306
}
299
307
300
308
/**
You can’t perform that action at this time.
0 commit comments