@@ -240,9 +240,10 @@ export class Collection implements OperationParent {
240
240
241
241
/**
242
242
* The current topology of the collection.
243
+ * @internal
243
244
*/
244
- get topology ( ) : Topology | undefined {
245
- return this . s . db . topology ;
245
+ getTopology ( ) : Topology | undefined {
246
+ return this . s . db . s . client . topology ;
246
247
}
247
248
248
249
/**
@@ -287,7 +288,7 @@ export class Collection implements OperationParent {
287
288
options = options || { } ;
288
289
289
290
return executeOperation (
290
- this . s . db . topology ,
291
+ this . getTopology ( ) ,
291
292
new InsertOneOperation ( this , doc , options ) ,
292
293
callback
293
294
) ;
@@ -319,7 +320,7 @@ export class Collection implements OperationParent {
319
320
options = options ? Object . assign ( { } , options ) : { ordered : true } ;
320
321
321
322
return executeOperation (
322
- this . s . db . topology ,
323
+ this . getTopology ( ) ,
323
324
new InsertManyOperation ( this , docs , options ) ,
324
325
callback
325
326
) ;
@@ -379,7 +380,7 @@ export class Collection implements OperationParent {
379
380
}
380
381
381
382
return executeOperation (
382
- this . s . db . topology ,
383
+ this . getTopology ( ) ,
383
384
new BulkWriteOperation ( this , operations , options ) ,
384
385
callback
385
386
) ;
@@ -412,7 +413,7 @@ export class Collection implements OperationParent {
412
413
options = Object . assign ( { } , options ) ;
413
414
414
415
return executeOperation (
415
- this . s . db . topology ,
416
+ this . getTopology ( ) ,
416
417
new UpdateOneOperation ( this , filter , update , options ) ,
417
418
callback
418
419
) ;
@@ -449,7 +450,7 @@ export class Collection implements OperationParent {
449
450
options = Object . assign ( { } , options ) ;
450
451
451
452
return executeOperation (
452
- this . s . db . topology ,
453
+ this . getTopology ( ) ,
453
454
new ReplaceOneOperation ( this , filter , replacement , options ) ,
454
455
callback
455
456
) ;
@@ -482,7 +483,7 @@ export class Collection implements OperationParent {
482
483
options = Object . assign ( { } , options ) ;
483
484
484
485
return executeOperation (
485
- this . s . db . topology ,
486
+ this . getTopology ( ) ,
486
487
new UpdateManyOperation ( this , filter , update , options ) ,
487
488
callback
488
489
) ;
@@ -508,7 +509,7 @@ export class Collection implements OperationParent {
508
509
options = Object . assign ( { } , options ) ;
509
510
510
511
return executeOperation (
511
- this . s . db . topology ,
512
+ this . getTopology ( ) ,
512
513
new DeleteOneOperation ( this , filter , options ) ,
513
514
callback
514
515
) ;
@@ -546,7 +547,7 @@ export class Collection implements OperationParent {
546
547
options = Object . assign ( { } , options ) ;
547
548
548
549
return executeOperation (
549
- this . s . db . topology ,
550
+ this . getTopology ( ) ,
550
551
new DeleteManyOperation ( this , filter , options ) ,
551
552
callback
552
553
) ;
@@ -572,7 +573,7 @@ export class Collection implements OperationParent {
572
573
options = Object . assign ( { } , options , { readPreference : ReadPreference . PRIMARY } ) ;
573
574
574
575
return executeOperation (
575
- this . s . db . topology ,
576
+ this . getTopology ( ) ,
576
577
new RenameOperation ( this , newName , options ) ,
577
578
callback
578
579
) ;
@@ -596,7 +597,7 @@ export class Collection implements OperationParent {
596
597
options = options || { } ;
597
598
598
599
return executeOperation (
599
- this . s . db . topology ,
600
+ this . getTopology ( ) ,
600
601
new DropCollectionOperation ( this . s . db , this . collectionName , options ) ,
601
602
callback
602
603
) ;
@@ -631,7 +632,7 @@ export class Collection implements OperationParent {
631
632
options = options || { } ;
632
633
633
634
return executeOperation (
634
- this . s . db . topology ,
635
+ this . getTopology ( ) ,
635
636
new FindOneOperation ( this , query , options ) ,
636
637
callback
637
638
) ;
@@ -653,9 +654,10 @@ export class Collection implements OperationParent {
653
654
throw new TypeError ( '`options` parameter must not be function' ) ;
654
655
}
655
656
656
- if ( ! this . s . db . topology ) throw new MongoClientClosedError ( ) ;
657
+ const topology = this . getTopology ( ) ;
658
+ if ( ! topology ) throw new MongoClientClosedError ( ) ;
657
659
return new Cursor (
658
- this . s . db . topology ,
660
+ topology ,
659
661
new FindOperation ( this , this . s . namespace , filter , options ) ,
660
662
options
661
663
) ;
@@ -678,7 +680,7 @@ export class Collection implements OperationParent {
678
680
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
679
681
options = options || { } ;
680
682
681
- return executeOperation ( this . s . db . topology , new OptionsOperation ( this , options ) , callback ) ;
683
+ return executeOperation ( this . getTopology ( ) , new OptionsOperation ( this , options ) , callback ) ;
682
684
}
683
685
684
686
/**
@@ -698,7 +700,7 @@ export class Collection implements OperationParent {
698
700
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
699
701
options = options || { } ;
700
702
701
- return executeOperation ( this . s . db . topology , new IsCappedOperation ( this , options ) , callback ) ;
703
+ return executeOperation ( this . getTopology ( ) , new IsCappedOperation ( this , options ) , callback ) ;
702
704
}
703
705
704
706
/**
@@ -747,7 +749,7 @@ export class Collection implements OperationParent {
747
749
options = options || { } ;
748
750
749
751
return executeOperation (
750
- this . s . db . topology ,
752
+ this . getTopology ( ) ,
751
753
new CreateIndexOperation ( this , this . collectionName , indexSpec , options ) ,
752
754
callback
753
755
) ;
@@ -803,7 +805,7 @@ export class Collection implements OperationParent {
803
805
if ( typeof options . maxTimeMS !== 'number' ) delete options . maxTimeMS ;
804
806
805
807
return executeOperation (
806
- this . s . db . topology ,
808
+ this . getTopology ( ) ,
807
809
new CreateIndexesOperation ( this , this . collectionName , indexSpecs , options ) ,
808
810
callback
809
811
) ;
@@ -832,7 +834,7 @@ export class Collection implements OperationParent {
832
834
options . readPreference = ReadPreference . primary ;
833
835
834
836
return executeOperation (
835
- this . s . db . topology ,
837
+ this . getTopology ( ) ,
836
838
new DropIndexOperation ( this , indexName , options ) ,
837
839
callback
838
840
) ;
@@ -855,7 +857,7 @@ export class Collection implements OperationParent {
855
857
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
856
858
options = options ? Object . assign ( { } , options ) : { } ;
857
859
858
- return executeOperation ( this . s . db . topology , new DropIndexesOperation ( this , options ) , callback ) ;
860
+ return executeOperation ( this . getTopology ( ) , new DropIndexesOperation ( this , options ) , callback ) ;
859
861
}
860
862
861
863
/**
@@ -864,12 +866,9 @@ export class Collection implements OperationParent {
864
866
* @param options - Optional settings for the command
865
867
*/
866
868
listIndexes ( options ?: ListIndexesOptions ) : CommandCursor {
867
- if ( ! this . s . db . topology ) throw new MongoClientClosedError ( ) ;
868
- const cursor = new CommandCursor (
869
- this . s . db . topology ,
870
- new ListIndexesOperation ( this , options ) ,
871
- options
872
- ) ;
869
+ const topology = this . getTopology ( ) ;
870
+ if ( ! topology ) throw new MongoClientClosedError ( ) ;
871
+ const cursor = new CommandCursor ( topology , new ListIndexesOperation ( this , options ) , options ) ;
873
872
874
873
return cursor ;
875
874
}
@@ -898,7 +897,7 @@ export class Collection implements OperationParent {
898
897
options = options || { } ;
899
898
900
899
return executeOperation (
901
- this . s . db . topology ,
900
+ this . getTopology ( ) ,
902
901
new IndexExistsOperation ( this , indexes , options ) ,
903
902
callback
904
903
) ;
@@ -922,7 +921,7 @@ export class Collection implements OperationParent {
922
921
options = options || { } ;
923
922
924
923
return executeOperation (
925
- this . s . db . topology ,
924
+ this . getTopology ( ) ,
926
925
new IndexInformationOperation ( this . s . db , this . collectionName , options ) ,
927
926
callback
928
927
) ;
@@ -946,7 +945,7 @@ export class Collection implements OperationParent {
946
945
options = options || { } ;
947
946
948
947
return executeOperation (
949
- this . s . db . topology ,
948
+ this . getTopology ( ) ,
950
949
new EstimatedDocumentCountOperation ( this , options ) ,
951
950
callback
952
951
) ;
@@ -1002,7 +1001,7 @@ export class Collection implements OperationParent {
1002
1001
query = query || { } ;
1003
1002
options = options || { } ;
1004
1003
return executeOperation (
1005
- this . s . db . topology ,
1004
+ this . getTopology ( ) ,
1006
1005
new CountDocumentsOperation ( this , query as Document , options as CountDocumentsOptions ) ,
1007
1006
callback
1008
1007
) ;
@@ -1044,7 +1043,7 @@ export class Collection implements OperationParent {
1044
1043
query = query || { } ;
1045
1044
options = options || { } ;
1046
1045
return executeOperation (
1047
- this . s . db . topology ,
1046
+ this . getTopology ( ) ,
1048
1047
new DistinctOperation ( this , key , query as Document , options as DistinctOptions ) ,
1049
1048
callback
1050
1049
) ;
@@ -1067,7 +1066,7 @@ export class Collection implements OperationParent {
1067
1066
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1068
1067
options = options || { } ;
1069
1068
1070
- return executeOperation ( this . s . db . topology , new IndexesOperation ( this , options ) , callback ) ;
1069
+ return executeOperation ( this . getTopology ( ) , new IndexesOperation ( this , options ) , callback ) ;
1071
1070
}
1072
1071
1073
1072
/**
@@ -1087,7 +1086,7 @@ export class Collection implements OperationParent {
1087
1086
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1088
1087
options = options || { } ;
1089
1088
1090
- return executeOperation ( this . s . db . topology , new CollStatsOperation ( this , options ) , callback ) ;
1089
+ return executeOperation ( this . getTopology ( ) , new CollStatsOperation ( this , options ) , callback ) ;
1091
1090
}
1092
1091
1093
1092
/**
@@ -1114,7 +1113,7 @@ export class Collection implements OperationParent {
1114
1113
options = options || { } ;
1115
1114
1116
1115
return executeOperation (
1117
- this . s . db . topology ,
1116
+ this . getTopology ( ) ,
1118
1117
new FindOneAndDeleteOperation ( this , filter , options ) ,
1119
1118
callback
1120
1119
) ;
@@ -1151,7 +1150,7 @@ export class Collection implements OperationParent {
1151
1150
options = options || { } ;
1152
1151
1153
1152
return executeOperation (
1154
- this . s . db . topology ,
1153
+ this . getTopology ( ) ,
1155
1154
new FindOneAndReplaceOperation ( this , filter , replacement , options ) ,
1156
1155
callback
1157
1156
) ;
@@ -1188,7 +1187,7 @@ export class Collection implements OperationParent {
1188
1187
options = options || { } ;
1189
1188
1190
1189
return executeOperation (
1191
- this . s . db . topology ,
1190
+ this . getTopology ( ) ,
1192
1191
new FindOneAndUpdateOperation ( this , filter , update , options ) ,
1193
1192
callback
1194
1193
) ;
@@ -1213,9 +1212,10 @@ export class Collection implements OperationParent {
1213
1212
1214
1213
options = options || { } ;
1215
1214
1216
- if ( ! this . s . db . topology ) throw new MongoClientClosedError ( ) ;
1215
+ const topology = this . getTopology ( ) ;
1216
+ if ( ! topology ) throw new MongoClientClosedError ( ) ;
1217
1217
return new AggregationCursor (
1218
- this . s . db . topology ,
1218
+ topology ,
1219
1219
new AggregateOperation ( this , pipeline , options ) ,
1220
1220
options
1221
1221
) ;
@@ -1298,7 +1298,7 @@ export class Collection implements OperationParent {
1298
1298
}
1299
1299
1300
1300
return executeOperation (
1301
- this . s . db . topology ,
1301
+ this . getTopology ( ) ,
1302
1302
new MapReduceOperation ( this , map , reduce , options ) ,
1303
1303
callback
1304
1304
) ;
@@ -1418,7 +1418,7 @@ export class Collection implements OperationParent {
1418
1418
options = options || { } ;
1419
1419
1420
1420
return executeOperation (
1421
- this . s . db . topology ,
1421
+ this . getTopology ( ) ,
1422
1422
new EnsureIndexOperation ( this . s . db , this . collectionName , fieldOrSpec , options ) ,
1423
1423
callback
1424
1424
) ;
@@ -1457,7 +1457,7 @@ export class Collection implements OperationParent {
1457
1457
query = query || { } ;
1458
1458
options = options || { } ;
1459
1459
return executeOperation (
1460
- this . s . db . topology ,
1460
+ this . getTopology ( ) ,
1461
1461
new EstimatedDocumentCountOperation ( this , query , options ) ,
1462
1462
callback
1463
1463
) ;
@@ -1506,7 +1506,7 @@ export class Collection implements OperationParent {
1506
1506
options . remove = true ;
1507
1507
1508
1508
return executeOperation (
1509
- this . s . db . topology ,
1509
+ this . getTopology ( ) ,
1510
1510
new FindAndModifyOperation ( this , query , sort as Sort , undefined , options ) ,
1511
1511
callback
1512
1512
) ;
@@ -1567,14 +1567,14 @@ export class Collection implements OperationParent {
1567
1567
1568
1568
if ( command == null ) {
1569
1569
return executeOperation (
1570
- this . s . db . topology ,
1570
+ this . getTopology ( ) ,
1571
1571
new EvalGroupOperation ( this , keys , condition , initial , reduce , finalize , options ) ,
1572
1572
callback
1573
1573
) ;
1574
1574
}
1575
1575
1576
1576
return executeOperation (
1577
- this . s . db . topology ,
1577
+ this . getTopology ( ) ,
1578
1578
new GroupOperation ( this , keys , condition , initial , reduce , finalize , options ) ,
1579
1579
callback
1580
1580
) ;
@@ -1625,7 +1625,7 @@ export class Collection implements OperationParent {
1625
1625
options . readPreference = ReadPreference . primary ;
1626
1626
1627
1627
return executeOperation (
1628
- this . s . db . topology ,
1628
+ this . getTopology ( ) ,
1629
1629
new FindAndModifyOperation ( this , query , sort , doc , options ) ,
1630
1630
callback
1631
1631
) ;
0 commit comments