@@ -58,7 +58,6 @@ export default class Database extends ShellApiWithMongoClass {
58
58
_mongo : Mongo ;
59
59
_name : string ;
60
60
_collections : Record < string , Collection > ;
61
- _baseOptions : CommandOperationOptions ;
62
61
_session : Session | undefined ;
63
62
_cachedCollectionNames : string [ ] = [ ] ;
64
63
@@ -68,11 +67,7 @@ export default class Database extends ShellApiWithMongoClass {
68
67
this . _name = name ;
69
68
const collections : Record < string , Collection > = { } ;
70
69
this . _collections = collections ;
71
- this . _baseOptions = { } ;
72
- if ( session !== undefined ) {
73
- this . _session = session ;
74
- this . _baseOptions . session = session . _session ;
75
- }
70
+ this . _session = session ;
76
71
const proxy = new Proxy ( this , {
77
72
get : ( target , prop ) : any => {
78
73
if ( prop in target ) {
@@ -97,6 +92,18 @@ export default class Database extends ShellApiWithMongoClass {
97
92
return proxy ;
98
93
}
99
94
95
+ async _baseOptions ( ) : Promise < CommandOperationOptions > {
96
+ const options : CommandOperationOptions = { } ;
97
+ if ( this . _session ) {
98
+ options . session = this . _session . _session ;
99
+ }
100
+ const maxTimeMS = await this . _internalState . shellApi . config . get ( 'maxTimeMS' ) ;
101
+ if ( typeof maxTimeMS === 'number' ) {
102
+ options . maxTimeMS = maxTimeMS ;
103
+ }
104
+ return options ;
105
+ }
106
+
100
107
/**
101
108
* Internal method to determine what is printed for this class.
102
109
*/
@@ -126,23 +133,23 @@ export default class Database extends ShellApiWithMongoClass {
126
133
return this . _mongo . _serviceProvider . runCommandWithCheck (
127
134
this . _name ,
128
135
cmd ,
129
- { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...this . _baseOptions , ...options }
136
+ { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...await this . _baseOptions ( ) , ...options }
130
137
) ;
131
138
}
132
139
133
140
public async _runAdminCommand ( cmd : Document , options : CommandOperationOptions = { } ) : Promise < Document > {
134
141
return this . _mongo . _serviceProvider . runCommandWithCheck (
135
142
ADMIN_DB ,
136
143
cmd ,
137
- { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...this . _baseOptions , ...options }
144
+ { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...await this . _baseOptions ( ) , ...options }
138
145
) ;
139
146
}
140
147
141
148
private async _listCollections ( filter : Document , options : ListCollectionsOptions ) : Promise < Document [ ] > {
142
149
return await this . _mongo . _serviceProvider . listCollections (
143
150
this . _name ,
144
151
filter ,
145
- { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...this . _baseOptions , ...options }
152
+ { ...this . _mongo . _getExplicitlyRequestedReadPref ( ) , ...await this . _baseOptions ( ) , ...options }
146
153
) || [ ] ;
147
154
}
148
155
@@ -202,7 +209,7 @@ export default class Database extends ShellApiWithMongoClass {
202
209
return await this . _mongo . _serviceProvider . runCommand (
203
210
this . _name ,
204
211
cmd ,
205
- this . _baseOptions
212
+ await this . _baseOptions ( )
206
213
) ;
207
214
} catch ( e ) {
208
215
return e ;
@@ -317,7 +324,7 @@ export default class Database extends ShellApiWithMongoClass {
317
324
const providerCursor = this . _mongo . _serviceProvider . aggregateDb (
318
325
this . _name ,
319
326
pipeline ,
320
- { ...this . _baseOptions , ...aggOptions } ,
327
+ { ...await this . _baseOptions ( ) , ...aggOptions } ,
321
328
dbOptions
322
329
) ;
323
330
const cursor = new AggregationCursor ( this . _mongo , providerCursor ) ;
@@ -362,7 +369,7 @@ export default class Database extends ShellApiWithMongoClass {
362
369
async dropDatabase ( writeConcern ?: WriteConcern ) : Promise < Document > {
363
370
return await this . _mongo . _serviceProvider . dropDatabase (
364
371
this . _name ,
365
- { ...this . _baseOptions , writeConcern }
372
+ { ...await this . _baseOptions ( ) , writeConcern }
366
373
) ;
367
374
}
368
375
@@ -591,7 +598,7 @@ export default class Database extends ShellApiWithMongoClass {
591
598
return await this . _mongo . _serviceProvider . createCollection (
592
599
this . _name ,
593
600
name ,
594
- { ...this . _baseOptions , ...options }
601
+ { ...await this . _baseOptions ( ) , ...options }
595
602
) ;
596
603
}
597
604
@@ -601,7 +608,7 @@ export default class Database extends ShellApiWithMongoClass {
601
608
assertArgsDefinedType ( [ name , source , pipeline ] , [ 'string' , 'string' , true ] , 'Database.createView' ) ;
602
609
this . _emitDatabaseApiCall ( 'createView' , { name, source, pipeline, options } ) ;
603
610
const ccOpts = {
604
- ...this . _baseOptions ,
611
+ ...await this . _baseOptions ( ) ,
605
612
viewOn : source ,
606
613
pipeline : pipeline
607
614
} as Document ;
@@ -1032,15 +1039,15 @@ export default class Database extends ShellApiWithMongoClass {
1032
1039
setFreeMonitoring : 1 ,
1033
1040
action : 'enable'
1034
1041
} ,
1035
- this . _baseOptions
1042
+ await this . _baseOptions ( )
1036
1043
) ;
1037
1044
let result : any ;
1038
1045
let error : any ;
1039
1046
try {
1040
1047
result = await this . _mongo . _serviceProvider . runCommand (
1041
1048
ADMIN_DB ,
1042
1049
{ getFreeMonitoringStatus : 1 } ,
1043
- this . _baseOptions
1050
+ await this . _baseOptions ( )
1044
1051
) ;
1045
1052
} catch ( err ) {
1046
1053
error = err ;
@@ -1060,7 +1067,7 @@ export default class Database extends ShellApiWithMongoClass {
1060
1067
getParameter : 1 ,
1061
1068
cloudFreeMonitoringEndpointURL : 1
1062
1069
} ,
1063
- this . _baseOptions
1070
+ await this . _baseOptions ( )
1064
1071
) ;
1065
1072
return `Unable to get immediate response from the Cloud Monitoring service. Please check your firewall settings to ensure that mongod can communicate with '${ urlResult . cloudFreeMonitoringEndpointURL || '<unknown>' } '` ;
1066
1073
}
@@ -1419,7 +1426,7 @@ export default class Database extends ShellApiWithMongoClass {
1419
1426
this . _emitDatabaseApiCall ( 'watch' , { pipeline, options } ) ;
1420
1427
const cursor = new ChangeStreamCursor (
1421
1428
this . _mongo . _serviceProvider . watch ( pipeline , {
1422
- ...this . _baseOptions ,
1429
+ ...await this . _baseOptions ( ) ,
1423
1430
...options
1424
1431
} , { } , this . _name ) ,
1425
1432
this . _name ,
0 commit comments