@@ -145,10 +145,10 @@ public ClientBulkWriteResult BulkWrite(IReadOnlyList<BulkWriteModel> models, Cli
145
145
/// <inheritdoc/>
146
146
public ClientBulkWriteResult BulkWrite ( IClientSessionHandle session , IReadOnlyList < BulkWriteModel > models , ClientBulkWriteOptions options = null , CancellationToken cancellationToken = default )
147
147
{
148
- ThrowIfDisposed ( ) ;
149
148
Ensure . IsNotNull ( session , nameof ( session ) ) ;
149
+ ThrowIfDisposed ( ) ;
150
150
var operation = CreateClientBulkWriteOperation ( models , options ) ;
151
- return ExecuteWriteOperation < ClientBulkWriteResult > ( session , operation , _writeOperationOptions , cancellationToken ) ;
151
+ return ExecuteWriteOperation < ClientBulkWriteResult > ( session , operation , cancellationToken ) ;
152
152
}
153
153
154
154
/// <inheritdoc/>
@@ -162,10 +162,10 @@ public async Task<ClientBulkWriteResult> BulkWriteAsync(IReadOnlyList<BulkWriteM
162
162
/// <inheritdoc/>
163
163
public Task < ClientBulkWriteResult > BulkWriteAsync ( IClientSessionHandle session , IReadOnlyList < BulkWriteModel > models , ClientBulkWriteOptions options = null , CancellationToken cancellationToken = default )
164
164
{
165
- ThrowIfDisposed ( ) ;
166
165
Ensure . IsNotNull ( session , nameof ( session ) ) ;
166
+ ThrowIfDisposed ( ) ;
167
167
var operation = CreateClientBulkWriteOperation ( models , options ) ;
168
- return ExecuteWriteOperationAsync < ClientBulkWriteResult > ( session , operation , _writeOperationOptions , cancellationToken ) ;
168
+ return ExecuteWriteOperationAsync < ClientBulkWriteResult > ( session , operation , cancellationToken ) ;
169
169
}
170
170
171
171
/// <inheritdoc/>
@@ -209,10 +209,10 @@ public void DropDatabase(string name, CancellationToken cancellationToken = defa
209
209
/// <inheritdoc/>
210
210
public void DropDatabase ( IClientSessionHandle session , string name , CancellationToken cancellationToken = default )
211
211
{
212
- ThrowIfDisposed ( ) ;
213
212
Ensure . IsNotNull ( session , nameof ( session ) ) ;
213
+ ThrowIfDisposed ( ) ;
214
214
var operation = CreateDropDatabaseOperation ( name ) ;
215
- ExecuteWriteOperation ( session , operation , _writeOperationOptions , cancellationToken ) ;
215
+ ExecuteWriteOperation ( session , operation , cancellationToken ) ;
216
216
}
217
217
218
218
/// <inheritdoc/>
@@ -226,10 +226,10 @@ public async Task DropDatabaseAsync(string name, CancellationToken cancellationT
226
226
/// <inheritdoc/>
227
227
public Task DropDatabaseAsync ( IClientSessionHandle session , string name , CancellationToken cancellationToken = default )
228
228
{
229
- ThrowIfDisposed ( ) ;
230
229
Ensure . IsNotNull ( session , nameof ( session ) ) ;
230
+ ThrowIfDisposed ( ) ;
231
231
var opertion = CreateDropDatabaseOperation ( name ) ;
232
- return ExecuteWriteOperationAsync ( session , opertion , _writeOperationOptions , cancellationToken ) ;
232
+ return ExecuteWriteOperationAsync ( session , opertion , cancellationToken ) ;
233
233
}
234
234
235
235
/// <inheritdoc/>
@@ -256,9 +256,8 @@ public IAsyncCursor<string> ListDatabaseNames(
256
256
CancellationToken cancellationToken = default )
257
257
{
258
258
ThrowIfDisposed ( ) ;
259
- var listDatabasesOptions = CreateListDatabasesOptionsFromListDatabaseNamesOptions ( options ) ;
260
- var databases = ListDatabases ( listDatabasesOptions , cancellationToken ) ;
261
- return CreateDatabaseNamesCursor ( databases ) ;
259
+ using var session = _operationExecutor . StartImplicitSession ( ) ;
260
+ return ListDatabaseNames ( session , options , cancellationToken ) ;
262
261
}
263
262
264
263
/// <inheritdoc />
@@ -289,9 +288,8 @@ public async Task<IAsyncCursor<string>> ListDatabaseNamesAsync(
289
288
CancellationToken cancellationToken = default )
290
289
{
291
290
ThrowIfDisposed ( ) ;
292
- var listDatabasesOptions = CreateListDatabasesOptionsFromListDatabaseNamesOptions ( options ) ;
293
- var databases = await ListDatabasesAsync ( listDatabasesOptions , cancellationToken ) . ConfigureAwait ( false ) ;
294
- return CreateDatabaseNamesCursor ( databases ) ;
291
+ using var session = _operationExecutor . StartImplicitSession ( ) ;
292
+ return await ListDatabaseNamesAsync ( session , options , cancellationToken ) . ConfigureAwait ( false ) ;
295
293
}
296
294
297
295
/// <inheritdoc />
@@ -334,12 +332,7 @@ public IAsyncCursor<BsonDocument> ListDatabases(
334
332
public IAsyncCursor < BsonDocument > ListDatabases (
335
333
IClientSessionHandle session ,
336
334
CancellationToken cancellationToken = default )
337
- {
338
- ThrowIfDisposed ( ) ;
339
- Ensure . IsNotNull ( session , nameof ( session ) ) ;
340
- var operation = CreateListDatabaseOperation ( null ) ;
341
- return ExecuteReadOperation ( session , operation , _readOperationOptions , cancellationToken ) ;
342
- }
335
+ => ListDatabases ( session , null , cancellationToken ) ;
343
336
344
337
/// <inheritdoc/>
345
338
public IAsyncCursor < BsonDocument > ListDatabases (
@@ -350,7 +343,7 @@ public IAsyncCursor<BsonDocument> ListDatabases(
350
343
ThrowIfDisposed ( ) ;
351
344
Ensure . IsNotNull ( session , nameof ( session ) ) ;
352
345
var operation = CreateListDatabaseOperation ( options ) ;
353
- return ExecuteReadOperation ( session , operation , _readOperationOptions , cancellationToken ) ;
346
+ return ExecuteReadOperation ( session , operation , cancellationToken ) ;
354
347
}
355
348
356
349
/// <inheritdoc/>
@@ -375,23 +368,18 @@ public async Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(
375
368
public Task < IAsyncCursor < BsonDocument > > ListDatabasesAsync (
376
369
IClientSessionHandle session ,
377
370
CancellationToken cancellationToken = default )
378
- {
379
- ThrowIfDisposed ( ) ;
380
- Ensure . IsNotNull ( session , nameof ( session ) ) ;
381
- var operation = CreateListDatabaseOperation ( null ) ;
382
- return ExecuteReadOperationAsync ( session , operation , _readOperationOptions , cancellationToken ) ;
383
- }
371
+ => ListDatabasesAsync ( session , null , cancellationToken ) ;
384
372
385
373
/// <inheritdoc/>
386
374
public Task < IAsyncCursor < BsonDocument > > ListDatabasesAsync (
387
375
IClientSessionHandle session ,
388
376
ListDatabasesOptions options ,
389
377
CancellationToken cancellationToken = default )
390
378
{
391
- ThrowIfDisposed ( ) ;
392
379
Ensure . IsNotNull ( session , nameof ( session ) ) ;
380
+ ThrowIfDisposed ( ) ;
393
381
var operation = CreateListDatabaseOperation ( options ) ;
394
- return ExecuteReadOperationAsync ( session , operation , _readOperationOptions , cancellationToken ) ;
382
+ return ExecuteReadOperationAsync ( session , operation , cancellationToken ) ;
395
383
}
396
384
397
385
/// <inheritdoc/>
@@ -428,10 +416,10 @@ public IChangeStreamCursor<TResult> Watch<TResult>(
428
416
ChangeStreamOptions options = null ,
429
417
CancellationToken cancellationToken = default )
430
418
{
431
- ThrowIfDisposed ( ) ;
432
419
Ensure . IsNotNull ( session , nameof ( session ) ) ;
420
+ ThrowIfDisposed ( ) ;
433
421
var operation = CreateChangeStreamOperation ( pipeline , options ) ;
434
- return ExecuteReadOperation ( session , operation , _readOperationOptions , cancellationToken ) ;
422
+ return ExecuteReadOperation ( session , operation , cancellationToken ) ;
435
423
}
436
424
437
425
/// <inheritdoc/>
@@ -452,17 +440,16 @@ public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(
452
440
ChangeStreamOptions options = null ,
453
441
CancellationToken cancellationToken = default )
454
442
{
455
- ThrowIfDisposed ( ) ;
456
443
Ensure . IsNotNull ( session , nameof ( session ) ) ;
444
+ ThrowIfDisposed ( ) ;
457
445
var operation = CreateChangeStreamOperation ( pipeline , options ) ;
458
- return ExecuteReadOperationAsync ( session , operation , _readOperationOptions , cancellationToken ) ;
446
+ return ExecuteReadOperationAsync ( session , operation , cancellationToken ) ;
459
447
}
460
448
461
449
/// <inheritdoc/>
462
450
public IMongoClient WithReadConcern ( ReadConcern readConcern )
463
451
{
464
452
Ensure . IsNotNull ( readConcern , nameof ( readConcern ) ) ;
465
-
466
453
ThrowIfDisposed ( ) ;
467
454
468
455
var newSettings = Settings . Clone ( ) ;
@@ -474,7 +461,6 @@ public IMongoClient WithReadConcern(ReadConcern readConcern)
474
461
public IMongoClient WithReadPreference ( ReadPreference readPreference )
475
462
{
476
463
Ensure . IsNotNull ( readPreference , nameof ( readPreference ) ) ;
477
-
478
464
ThrowIfDisposed ( ) ;
479
465
480
466
var newSettings = Settings . Clone ( ) ;
@@ -486,7 +472,6 @@ public IMongoClient WithReadPreference(ReadPreference readPreference)
486
472
public IMongoClient WithWriteConcern ( WriteConcern writeConcern )
487
473
{
488
474
Ensure . IsNotNull ( writeConcern , nameof ( writeConcern ) ) ;
489
-
490
475
ThrowIfDisposed ( ) ;
491
476
492
477
var newSettings = Settings . Clone ( ) ;
@@ -577,17 +562,17 @@ private ChangeStreamOperation<TResult> CreateChangeStreamOperation<TResult>(
577
562
_settings . RetryReads ,
578
563
_settings . TranslationOptions ) ;
579
564
580
- private TResult ExecuteReadOperation < TResult > ( IClientSessionHandle session , IReadOperation < TResult > operation , ReadOperationOptions options , CancellationToken cancellationToken )
581
- => _operationExecutor . ExecuteReadOperation ( session , operation , options , false , cancellationToken ) ;
565
+ private TResult ExecuteReadOperation < TResult > ( IClientSessionHandle session , IReadOperation < TResult > operation , CancellationToken cancellationToken )
566
+ => _operationExecutor . ExecuteReadOperation ( session , operation , _readOperationOptions , false , cancellationToken ) ;
582
567
583
- private Task < TResult > ExecuteReadOperationAsync < TResult > ( IClientSessionHandle session , IReadOperation < TResult > operation , ReadOperationOptions options , CancellationToken cancellationToken )
584
- => _operationExecutor . ExecuteReadOperationAsync ( session , operation , options , false , cancellationToken ) ;
568
+ private Task < TResult > ExecuteReadOperationAsync < TResult > ( IClientSessionHandle session , IReadOperation < TResult > operation , CancellationToken cancellationToken )
569
+ => _operationExecutor . ExecuteReadOperationAsync ( session , operation , _readOperationOptions , false , cancellationToken ) ;
585
570
586
- private TResult ExecuteWriteOperation < TResult > ( IClientSessionHandle session , IWriteOperation < TResult > operation , WriteOperationOptions options , CancellationToken cancellationToken )
587
- => _operationExecutor . ExecuteWriteOperation ( session , operation , options , false , cancellationToken ) ;
571
+ private TResult ExecuteWriteOperation < TResult > ( IClientSessionHandle session , IWriteOperation < TResult > operation , CancellationToken cancellationToken )
572
+ => _operationExecutor . ExecuteWriteOperation ( session , operation , _writeOperationOptions , false , cancellationToken ) ;
588
573
589
- private Task < TResult > ExecuteWriteOperationAsync < TResult > ( IClientSessionHandle session , IWriteOperation < TResult > operation , WriteOperationOptions options , CancellationToken cancellationToken )
590
- => _operationExecutor . ExecuteWriteOperationAsync ( session , operation , options , false , cancellationToken ) ;
574
+ private Task < TResult > ExecuteWriteOperationAsync < TResult > ( IClientSessionHandle session , IWriteOperation < TResult > operation , CancellationToken cancellationToken )
575
+ => _operationExecutor . ExecuteWriteOperationAsync ( session , operation , _writeOperationOptions , false , cancellationToken ) ;
591
576
592
577
private MessageEncoderSettings GetMessageEncoderSettings ( )
593
578
{
0 commit comments