File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -78,18 +78,21 @@ export function executeOperation<
78
78
return maybeCallback ( ( ) => executeOperationAsync ( client , operation ) , callback ) ;
79
79
}
80
80
81
- async function assertTopology ( client : MongoClient ) {
81
+ async function maybeConnect ( client : MongoClient ) : Promise < Topology > {
82
82
const { topology } = client ;
83
83
if ( topology == null ) {
84
84
if ( client . s . hasBeenClosed ) {
85
85
throw new MongoNotConnectedError ( 'Client must be connected before running operations' ) ;
86
86
}
87
87
client . s . options [ Symbol . for ( '@@mdb.skipPingOnConnect' ) ] = true ;
88
- await client . connect ( ) ;
89
- delete client . s . options [ Symbol . for ( '@@mdb.skipPingOnConnect' ) ] ;
88
+ try {
89
+ await client . connect ( ) ;
90
+ } finally {
91
+ delete client . s . options [ Symbol . for ( '@@mdb.skipPingOnConnect' ) ] ;
92
+ }
90
93
}
91
94
if ( client . topology == null ) {
92
- throw new MongoNotConnectedError ( 'Client must be connected before running operations ') ;
95
+ throw new MongoRuntimeError ( 'client.connect did not create a topology but also did not throw ') ;
93
96
}
94
97
return client . topology ;
95
98
}
@@ -103,7 +106,7 @@ async function executeOperationAsync<
103
106
throw new MongoRuntimeError ( 'This method requires a valid operation instance' ) ;
104
107
}
105
108
106
- const topology = await assertTopology ( client ) ;
109
+ const topology = await maybeConnect ( client ) ;
107
110
108
111
if ( topology . shouldCheckForSessionSupport ( ) ) {
109
112
await topology . selectServerAsync ( ReadPreference . primaryPreferred , { } ) ;
Original file line number Diff line number Diff line change @@ -38,7 +38,11 @@ export class RenameOperation extends RunAdminCommandOperation {
38
38
this . newName = newName ;
39
39
}
40
40
41
- override execute ( server : Server , session : ClientSession | undefined , callback : Callback ) : void {
41
+ override execute (
42
+ server : Server ,
43
+ session : ClientSession | undefined ,
44
+ callback : Callback < Collection >
45
+ ) : void {
42
46
const coll = this . collection ;
43
47
44
48
super . execute ( server , session , ( err , doc ) => {
Original file line number Diff line number Diff line change @@ -33,7 +33,11 @@ export class CollStatsOperation extends CommandOperation<Document> {
33
33
this . collectionName = collection . collectionName ;
34
34
}
35
35
36
- override execute ( server : Server , session : ClientSession | undefined , callback : Callback ) : void {
36
+ override execute (
37
+ server : Server ,
38
+ session : ClientSession | undefined ,
39
+ callback : Callback < CollStats >
40
+ ) : void {
37
41
const command : Document = { collStats : this . collectionName } ;
38
42
if ( this . options . scale != null ) {
39
43
command . scale = this . options . scale ;
You can’t perform that action at this time.
0 commit comments