1- /* Copyright 2013 -present MongoDB Inc.
1+ /* Copyright 2010 -present MongoDB Inc.
22*
33* Licensed under the Apache License, Version 2.0 (the "License");
44* you may not use this file except in compliance with the License.
@@ -157,7 +157,7 @@ public BsonDocument Execute(OperationContext operationContext, IWriteBinding bin
157157 using ( var channel = channelSource . GetChannel ( operationContext ) )
158158 using ( var channelBinding = new ChannelReadWriteBinding ( channelSource . Server , channel , binding . Session . Fork ( ) ) )
159159 {
160- var operation = CreateOperation ( channelBinding . Session , channel . ConnectionDescription , mayUseSecondary . EffectiveReadPreference ) ;
160+ var operation = CreateOperation ( operationContext , channelBinding . Session , channel . ConnectionDescription , mayUseSecondary . EffectiveReadPreference ) ;
161161 return operation . Execute ( operationContext , channelBinding ) ;
162162 }
163163 }
@@ -172,12 +172,12 @@ public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext,
172172 using ( var channel = await channelSource . GetChannelAsync ( operationContext ) . ConfigureAwait ( false ) )
173173 using ( var channelBinding = new ChannelReadWriteBinding ( channelSource . Server , channel , binding . Session . Fork ( ) ) )
174174 {
175- var operation = CreateOperation ( channelBinding . Session , channel . ConnectionDescription , mayUseSecondary . EffectiveReadPreference ) ;
175+ var operation = CreateOperation ( operationContext , channelBinding . Session , channel . ConnectionDescription , mayUseSecondary . EffectiveReadPreference ) ;
176176 return await operation . ExecuteAsync ( operationContext , channelBinding ) . ConfigureAwait ( false ) ;
177177 }
178178 }
179179
180- public BsonDocument CreateCommand ( ICoreSessionHandle session , ConnectionDescription connectionDescription )
180+ public BsonDocument CreateCommand ( OperationContext operationContext , ICoreSessionHandle session , ConnectionDescription connectionDescription )
181181 {
182182 var readConcern = _readConcern != null
183183 ? ReadConcernHelper . GetReadConcernForCommand ( session , connectionDescription , _readConcern )
@@ -189,7 +189,7 @@ public BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescript
189189 { "pipeline" , new BsonArray ( _pipeline ) } ,
190190 { "allowDiskUse" , ( ) => _allowDiskUse . Value , _allowDiskUse . HasValue } ,
191191 { "bypassDocumentValidation" , ( ) => _bypassDocumentValidation . Value , _bypassDocumentValidation . HasValue } ,
192- { "maxTimeMS" , ( ) => MaxTimeHelper . ToMaxTimeMS ( _maxTime . Value ) , _maxTime . HasValue } ,
192+ { "maxTimeMS" , ( ) => MaxTimeHelper . ToMaxTimeMS ( _maxTime . Value ) , _maxTime . HasValue && ! operationContext . IsRootContextTimeoutConfigured ( ) } ,
193193 { "collation" , ( ) => _collation . ToBsonDocument ( ) , _collation != null } ,
194194 { "readConcern" , readConcern , readConcern != null } ,
195195 { "writeConcern" , writeConcern , writeConcern != null } ,
@@ -202,9 +202,9 @@ public BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescript
202202
203203 private IDisposable BeginOperation ( ) => EventContext . BeginOperation ( "aggregate" ) ;
204204
205- private WriteCommandOperation < BsonDocument > CreateOperation ( ICoreSessionHandle session , ConnectionDescription connectionDescription , ReadPreference effectiveReadPreference )
205+ private WriteCommandOperation < BsonDocument > CreateOperation ( OperationContext operationContext , ICoreSessionHandle session , ConnectionDescription connectionDescription , ReadPreference effectiveReadPreference )
206206 {
207- var command = CreateCommand ( session , connectionDescription ) ;
207+ var command = CreateCommand ( operationContext , session , connectionDescription ) ;
208208 var operation = new WriteCommandOperation < BsonDocument > ( _databaseNamespace , command , BsonDocumentSerializer . Instance , MessageEncoderSettings ) ;
209209 if ( effectiveReadPreference != null )
210210 {
0 commit comments