Skip to content

Commit 416d3ce

Browse files
committed
be consistent with db topology access
1 parent 642d882 commit 416d3ce

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

src/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export class Collection implements OperationParent {
243243
* @internal
244244
*/
245245
getTopology(): Topology | undefined {
246-
return this.s.db.s.client.topology;
246+
return this.s.db.topology;
247247
}
248248

249249
/**

src/db.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class Db implements OperationParent {
260260
options.readConcern = ReadConcern.fromOptions(options) ?? this.readConcern;
261261

262262
return executeOperation(
263-
this.s.client.topology,
263+
this.topology,
264264
new CreateCollectionOperation(this, name, options),
265265
callback
266266
);
@@ -286,7 +286,7 @@ export class Db implements OperationParent {
286286
options = options || {};
287287

288288
return executeOperation(
289-
this.s.client.topology,
289+
this.topology,
290290
new RunCommandOperation(this, command, options),
291291
callback
292292
);
@@ -311,9 +311,9 @@ export class Db implements OperationParent {
311311

312312
options = options || {};
313313

314-
if (!this.s.client.topology) throw new MongoClientClosedError('Db.prototype.aggregate');
314+
if (!this.topology) throw new MongoClientClosedError('Db.prototype.aggregate');
315315
const cursor = new AggregationCursor(
316-
this.s.client.topology,
316+
this.topology,
317317
new AggregateOperation(this, pipeline, options),
318318
options
319319
);
@@ -377,7 +377,7 @@ export class Db implements OperationParent {
377377
}
378378

379379
// Did the user destroy the topology
380-
if (this.s.client.topology && this.s.client.topology.isDestroyed()) {
380+
if (this.topology && this.topology.isDestroyed()) {
381381
return callback(new MongoError('topology was destroyed'));
382382
}
383383

@@ -419,7 +419,7 @@ export class Db implements OperationParent {
419419
if (typeof options === 'function') (callback = options), (options = {});
420420
options = options || {};
421421

422-
return executeOperation(this.s.client.topology, new DbStatsOperation(this, options), callback);
422+
return executeOperation(this.topology, new DbStatsOperation(this, options), callback);
423423
}
424424

425425
/**
@@ -432,9 +432,9 @@ export class Db implements OperationParent {
432432
filter = filter || {};
433433
options = options || {};
434434

435-
if (!this.s.client.topology) throw new MongoClientClosedError('Db.prototype.listCollections');
435+
if (!this.topology) throw new MongoClientClosedError('Db.prototype.listCollections');
436436
return new CommandCursor(
437-
this.s.client.topology,
437+
this.topology,
438438
new ListCollectionsOperation(this, filter, options),
439439
options
440440
);
@@ -478,7 +478,7 @@ export class Db implements OperationParent {
478478
options.new_collection = true;
479479

480480
return executeOperation(
481-
this.s.client.topology,
481+
this.topology,
482482
new RenameOperation(this.collection(fromCollection), toCollection, options),
483483
callback
484484
);
@@ -504,7 +504,7 @@ export class Db implements OperationParent {
504504
options = options || {};
505505

506506
return executeOperation(
507-
this.s.client.topology,
507+
this.topology,
508508
new DropCollectionOperation(this, name, options),
509509
callback
510510
);
@@ -527,11 +527,7 @@ export class Db implements OperationParent {
527527
if (typeof options === 'function') (callback = options), (options = {});
528528
options = options || {};
529529

530-
return executeOperation(
531-
this.s.client.topology,
532-
new DropDatabaseOperation(this, options),
533-
callback
534-
);
530+
return executeOperation(this.topology, new DropDatabaseOperation(this, options), callback);
535531
}
536532

537533
/**
@@ -551,11 +547,7 @@ export class Db implements OperationParent {
551547
if (typeof options === 'function') (callback = options), (options = {});
552548
options = options || {};
553549

554-
return executeOperation(
555-
this.s.client.topology,
556-
new CollectionsOperation(this, options),
557-
callback
558-
);
550+
return executeOperation(this.topology, new CollectionsOperation(this, options), callback);
559551
}
560552

561553
/**
@@ -582,7 +574,7 @@ export class Db implements OperationParent {
582574
options = options || {};
583575

584576
return executeOperation(
585-
this.s.client.topology,
577+
this.topology,
586578
new RunAdminCommandOperation(this, command, options),
587579
callback
588580
);
@@ -619,7 +611,7 @@ export class Db implements OperationParent {
619611
options = options ? Object.assign({}, options) : {};
620612

621613
return executeOperation(
622-
this.s.client.topology,
614+
this.topology,
623615
new CreateIndexOperation(this, name, indexSpec, options),
624616
callback
625617
);
@@ -666,7 +658,7 @@ export class Db implements OperationParent {
666658

667659
options = options || {};
668660
return executeOperation(
669-
this.s.client.topology,
661+
this.topology,
670662
new AddUserOperation(this, username, password, options),
671663
callback
672664
);
@@ -692,7 +684,7 @@ export class Db implements OperationParent {
692684
options = options || {};
693685

694686
return executeOperation(
695-
this.s.client.topology,
687+
this.topology,
696688
new RemoveUserOperation(this, username, options),
697689
callback
698690
);
@@ -725,7 +717,7 @@ export class Db implements OperationParent {
725717
options = options || {};
726718

727719
return executeOperation(
728-
this.s.client.topology,
720+
this.topology,
729721
new SetProfilingLevelOperation(this, level, options),
730722
callback
731723
);
@@ -748,11 +740,7 @@ export class Db implements OperationParent {
748740
if (typeof options === 'function') (callback = options), (options = {});
749741
options = options || {};
750742

751-
return executeOperation(
752-
this.s.client.topology,
753-
new ProfilingLevelOperation(this, options),
754-
callback
755-
);
743+
return executeOperation(this.topology, new ProfilingLevelOperation(this, options), callback);
756744
}
757745

758746
/**
@@ -779,16 +767,16 @@ export class Db implements OperationParent {
779767
options = options || {};
780768

781769
return executeOperation(
782-
this.s.client.topology,
770+
this.topology,
783771
new IndexInformationOperation(this, name, options),
784772
callback
785773
);
786774
}
787775

788776
/** Unref all sockets */
789777
unref(): void {
790-
if (this.s.client.topology) {
791-
this.s.client.topology.unref();
778+
if (this.topology) {
779+
this.topology.unref();
792780
}
793781
}
794782

@@ -852,7 +840,7 @@ export class Db implements OperationParent {
852840
options = options || {};
853841

854842
return executeOperation(
855-
this.s.client.topology,
843+
this.topology,
856844
new EvalOperation(this, code, parameters, options),
857845
callback
858846
);
@@ -890,7 +878,7 @@ export class Db implements OperationParent {
890878
options = options || {};
891879

892880
return executeOperation(
893-
this.s.client.topology,
881+
this.topology,
894882
new EnsureIndexOperation(this, name, fieldOrSpec, options),
895883
callback
896884
);

0 commit comments

Comments
 (0)