@@ -31,7 +31,8 @@ const monitoringEvents = [
3131 'ping' ,
3232 'ha' ,
3333 'all' ,
34- 'fullsetup'
34+ 'fullsetup' ,
35+ 'open'
3536] ;
3637const ignoreOptionNames = [ 'native_parser' ] ;
3738const legacyOptionNames = [ 'server' , 'replset' , 'replSet' , 'mongos' , 'db' ] ;
@@ -132,11 +133,11 @@ function collectEvents(mongoClient, topology) {
132133 if ( mongoClient instanceof MongoClient ) {
133134 monitoringEvents . forEach ( event => {
134135 topology . on ( event , ( object1 , object2 ) => {
135- collectedEvents . push ( {
136- event : event ,
137- object1 : object1 ,
138- object2 : object2
139- } ) ;
136+ if ( event === 'open' ) {
137+ collectedEvents . push ( { event : event , object1 : mongoClient } ) ;
138+ } else {
139+ collectedEvents . push ( { event : event , object1 : object1 , object2 : object2 } ) ;
140+ }
140141 } ) ;
141142 } ) ;
142143 }
@@ -346,11 +347,11 @@ function createServer(mongoClient, options, callback) {
346347 // Set default options
347348 const servers = translateOptions ( options ) ;
348349
349- // Propagate the events to the client
350- const collectedEvents = collectEvents ( mongoClient , servers [ 0 ] ) ;
351-
352350 const server = servers [ 0 ] ;
353351
352+ // Propagate the events to the client
353+ const collectedEvents = collectEvents ( mongoClient , server ) ;
354+
354355 // Connect to topology
355356 server . connect ( options , ( err , topology ) => {
356357 if ( err ) {
@@ -389,8 +390,11 @@ function createTopology(mongoClient, topologyType, options, callback) {
389390 // Pass in the promise library
390391 options . promiseLibrary = mongoClient . s . promiseLibrary ;
391392
393+ const translationOptions = { } ;
394+ if ( topologyType === 'unified' ) translationOptions . createServers = false ;
395+
392396 // Set default options
393- const servers = translateOptions ( options ) ;
397+ const servers = translateOptions ( options , translationOptions ) ;
394398
395399 // Create the topology
396400 let topology ;
@@ -571,7 +575,9 @@ function transformUrlOptions(_object) {
571575 return object ;
572576}
573577
574- function translateOptions ( options ) {
578+ function translateOptions ( options , translationOptions ) {
579+ translationOptions = Object . assign ( { } , { createServers : true } , translationOptions ) ;
580+
575581 // If we have a readPreference passed in by the db options
576582 if ( typeof options . readPreference === 'string' || typeof options . read_preference === 'string' ) {
577583 options . readPreference = new ReadPreference ( options . readPreference || options . read_preference ) ;
@@ -591,6 +597,10 @@ function translateOptions(options) {
591597 if ( options . socketTimeoutMS == null ) options . socketTimeoutMS = 360000 ;
592598 if ( options . connectTimeoutMS == null ) options . connectTimeoutMS = 30000 ;
593599
600+ if ( ! translationOptions . createServers ) {
601+ return ;
602+ }
603+
594604 // Create server instances
595605 return options . servers . map ( serverObj => {
596606 return serverObj . domain_socket
0 commit comments