Skip to content

Commit 588cbec

Browse files
committed
create getTopology util
1 parent d2a1e75 commit 588cbec

File tree

16 files changed

+130
-130
lines changed

16 files changed

+130
-130
lines changed

src/admin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './operations/list_databases';
1212
import { executeOperation } from './operations/execute_operation';
1313
import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
14-
import type { Callback } from './utils';
14+
import { Callback, getTopology } from './utils';
1515
import type { Document } from './bson';
1616
import type { CommandOperationOptions } from './operations/command';
1717
import type { Db } from './db';
@@ -80,7 +80,7 @@ export class Admin {
8080
options = Object.assign({ dbName: 'admin' }, options);
8181

8282
return executeOperation(
83-
this.s.db.topology,
83+
getTopology(this.s.db),
8484
new RunCommandOperation(this.s.db, command, options),
8585
callback
8686
);
@@ -204,7 +204,7 @@ export class Admin {
204204
options = Object.assign({ dbName: 'admin' }, options);
205205

206206
return executeOperation(
207-
this.s.db.topology,
207+
getTopology(this.s.db),
208208
new AddUserOperation(this.s.db, username, password, options),
209209
callback
210210
);
@@ -230,7 +230,7 @@ export class Admin {
230230
options = Object.assign({ dbName: 'admin' }, options);
231231

232232
return executeOperation(
233-
this.s.db.topology,
233+
getTopology(this.s.db),
234234
new RemoveUserOperation(this.s.db, username, options),
235235
callback
236236
);
@@ -260,7 +260,7 @@ export class Admin {
260260
options = options || {};
261261

262262
return executeOperation(
263-
this.s.db.topology,
263+
getTopology(this.s.db),
264264
new ValidateCollectionOperation(this, collectionName, options),
265265
callback
266266
);
@@ -284,7 +284,7 @@ export class Admin {
284284
options = options || {};
285285

286286
return executeOperation(
287-
this.s.db.topology,
287+
getTopology(this.s.db),
288288
new ListDatabasesOperation(this.s.db, options),
289289
callback
290290
);

src/bulk/common.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
hasAtomicOperators,
99
Callback,
1010
MongoDBNamespace,
11-
maxWireVersion
11+
maxWireVersion,
12+
getTopology
1213
} from '../utils';
1314
import { executeOperation } from '../operations/execute_operation';
1415
import { InsertOperation } from '../operations/insert';
@@ -908,7 +909,7 @@ export abstract class BulkOperationBase {
908909
// determine whether bulkOperation is ordered or unordered
909910
this.isOrdered = isOrdered;
910911

911-
const topology = collection.getTopology();
912+
const topology = getTopology(collection);
912913
if (!topology) throw new MongoClientClosedError();
913914
options = options == null ? {} : options;
914915
// TODO Bring from driver information in isMaster

src/change_stream.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
now,
1212
maybePromise,
1313
MongoDBNamespace,
14-
Callback
14+
Callback,
15+
getTopology
1516
} from './utils';
1617
import type { ReadPreference } from './read_preference';
1718
import type { Timestamp, Document } from './bson';
@@ -221,22 +222,19 @@ export class ChangeStream extends EventEmitter {
221222
this.parent = parent;
222223
this.namespace = parent.s.namespace;
223224

224-
let topology: Topology | undefined;
225225
if (parent instanceof Collection) {
226226
this.type = CHANGE_DOMAIN_TYPES.COLLECTION;
227-
topology = parent.getTopology();
228227
} else if (parent instanceof Db) {
229228
this.type = CHANGE_DOMAIN_TYPES.DATABASE;
230-
topology = parent.topology;
231229
} else if (parent instanceof MongoClient) {
232230
this.type = CHANGE_DOMAIN_TYPES.CLUSTER;
233-
topology = parent.topology;
234231
} else {
235232
throw new TypeError(
236233
'parent provided to ChangeStream constructor is not an instance of Collection, Db, or MongoClient'
237234
);
238235
}
239236

237+
const topology = getTopology(parent);
240238
if (!topology) throw new MongoClientClosedError();
241239
this.topology = topology;
242240

0 commit comments

Comments
 (0)