@@ -31,7 +31,8 @@ const monitoringEvents = [
31
31
'ping' ,
32
32
'ha' ,
33
33
'all' ,
34
- 'fullsetup'
34
+ 'fullsetup' ,
35
+ 'open'
35
36
] ;
36
37
const ignoreOptionNames = [ 'native_parser' ] ;
37
38
const legacyOptionNames = [ 'server' , 'replset' , 'replSet' , 'mongos' , 'db' ] ;
@@ -132,11 +133,11 @@ function collectEvents(mongoClient, topology) {
132
133
if ( mongoClient instanceof MongoClient ) {
133
134
monitoringEvents . forEach ( event => {
134
135
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
+ }
140
141
} ) ;
141
142
} ) ;
142
143
}
@@ -346,11 +347,11 @@ function createServer(mongoClient, options, callback) {
346
347
// Set default options
347
348
const servers = translateOptions ( options ) ;
348
349
349
- // Propagate the events to the client
350
- const collectedEvents = collectEvents ( mongoClient , servers [ 0 ] ) ;
351
-
352
350
const server = servers [ 0 ] ;
353
351
352
+ // Propagate the events to the client
353
+ const collectedEvents = collectEvents ( mongoClient , server ) ;
354
+
354
355
// Connect to topology
355
356
server . connect ( options , ( err , topology ) => {
356
357
if ( err ) {
@@ -389,8 +390,11 @@ function createTopology(mongoClient, topologyType, options, callback) {
389
390
// Pass in the promise library
390
391
options . promiseLibrary = mongoClient . s . promiseLibrary ;
391
392
393
+ const translationOptions = { } ;
394
+ if ( topologyType === 'unified' ) translationOptions . createServers = false ;
395
+
392
396
// Set default options
393
- const servers = translateOptions ( options ) ;
397
+ const servers = translateOptions ( options , translationOptions ) ;
394
398
395
399
// Create the topology
396
400
let topology ;
@@ -571,7 +575,9 @@ function transformUrlOptions(_object) {
571
575
return object ;
572
576
}
573
577
574
- function translateOptions ( options ) {
578
+ function translateOptions ( options , translationOptions ) {
579
+ translationOptions = Object . assign ( { } , { createServers : true } , translationOptions ) ;
580
+
575
581
// If we have a readPreference passed in by the db options
576
582
if ( typeof options . readPreference === 'string' || typeof options . read_preference === 'string' ) {
577
583
options . readPreference = new ReadPreference ( options . readPreference || options . read_preference ) ;
@@ -591,6 +597,10 @@ function translateOptions(options) {
591
597
if ( options . socketTimeoutMS == null ) options . socketTimeoutMS = 360000 ;
592
598
if ( options . connectTimeoutMS == null ) options . connectTimeoutMS = 30000 ;
593
599
600
+ if ( ! translationOptions . createServers ) {
601
+ return ;
602
+ }
603
+
594
604
// Create server instances
595
605
return options . servers . map ( serverObj => {
596
606
return serverObj . domain_socket
0 commit comments