Skip to content

Commit 7a50664

Browse files
committed
push error check to execute operation
1 parent 147e78b commit 7a50664

File tree

6 files changed

+17
-73
lines changed

6 files changed

+17
-73
lines changed

src/admin.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type { Callback } from './utils';
1515
import type { Document } from './bson';
1616
import type { CommandOperationOptions } from './operations/command';
1717
import type { Db } from './db';
18-
import { MongoClientClosedError } from './error';
1918

2019
/** @internal */
2120
export interface AdminPrivate {
@@ -80,7 +79,6 @@ export class Admin {
8079
if (typeof options === 'function') (callback = options), (options = {});
8180
options = Object.assign({ dbName: 'admin' }, options);
8281

83-
if (!this.s.db.topology) throw new MongoClientClosedError();
8482
return executeOperation(
8583
this.s.db.topology,
8684
new RunCommandOperation(this.s.db, command, options),
@@ -205,7 +203,6 @@ export class Admin {
205203

206204
options = Object.assign({ dbName: 'admin' }, options);
207205

208-
if (!this.s.db.topology) throw new MongoClientClosedError();
209206
return executeOperation(
210207
this.s.db.topology,
211208
new AddUserOperation(this.s.db, username, password, options),
@@ -232,7 +229,6 @@ export class Admin {
232229
if (typeof options === 'function') (callback = options), (options = {});
233230
options = Object.assign({ dbName: 'admin' }, options);
234231

235-
if (!this.s.db.topology) throw new MongoClientClosedError();
236232
return executeOperation(
237233
this.s.db.topology,
238234
new RemoveUserOperation(this.s.db, username, options),
@@ -263,7 +259,6 @@ export class Admin {
263259
if (typeof options === 'function') (callback = options), (options = {});
264260
options = options || {};
265261

266-
if (!this.s.db.topology) throw new MongoClientClosedError();
267262
return executeOperation(
268263
this.s.db.topology,
269264
new ValidateCollectionOperation(this, collectionName, options),
@@ -288,7 +283,6 @@ export class Admin {
288283
if (typeof options === 'function') (callback = options), (options = {});
289284
options = options || {};
290285

291-
if (!this.s.db.topology) throw new MongoClientClosedError();
292286
return executeOperation(
293287
this.s.db.topology,
294288
new ListDatabasesOperation(this.s.db, options),

src/collection.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ export class Collection implements OperationParent {
313313
options.ignoreUndefined = this.s.options.ignoreUndefined;
314314
}
315315

316-
if (!this.s.db.topology) throw new MongoClientClosedError();
317316
return executeOperation(
318317
this.s.db.topology,
319318
new InsertOneOperation(this, doc, options),
@@ -346,7 +345,6 @@ export class Collection implements OperationParent {
346345
if (typeof options === 'function') (callback = options), (options = {});
347346
options = options ? Object.assign({}, options) : { ordered: true };
348347

349-
if (!this.s.db.topology) throw new MongoClientClosedError();
350348
return executeOperation(
351349
this.s.db.topology,
352350
new InsertManyOperation(this, docs, options),
@@ -407,7 +405,6 @@ export class Collection implements OperationParent {
407405
throw new MongoError('operations must be an array of documents');
408406
}
409407

410-
if (!this.s.db.topology) throw new MongoClientClosedError();
411408
return executeOperation(
412409
this.s.db.topology,
413410
new BulkWriteOperation(this, operations, options),
@@ -447,7 +444,6 @@ export class Collection implements OperationParent {
447444
options.ignoreUndefined = this.s.options.ignoreUndefined;
448445
}
449446

450-
if (!this.s.db.topology) throw new MongoClientClosedError();
451447
return executeOperation(
452448
this.s.db.topology,
453449
new UpdateOneOperation(this, filter, update, options),
@@ -491,7 +487,6 @@ export class Collection implements OperationParent {
491487
options.ignoreUndefined = this.s.options.ignoreUndefined;
492488
}
493489

494-
if (!this.s.db.topology) throw new MongoClientClosedError();
495490
return executeOperation(
496491
this.s.db.topology,
497492
new ReplaceOneOperation(this, filter, replacement, options),
@@ -531,7 +526,6 @@ export class Collection implements OperationParent {
531526
options.ignoreUndefined = this.s.options.ignoreUndefined;
532527
}
533528

534-
if (!this.s.db.topology) throw new MongoClientClosedError();
535529
return executeOperation(
536530
this.s.db.topology,
537531
new UpdateManyOperation(this, filter, update, options),
@@ -564,7 +558,6 @@ export class Collection implements OperationParent {
564558
options.ignoreUndefined = this.s.options.ignoreUndefined;
565559
}
566560

567-
if (!this.s.db.topology) throw new MongoClientClosedError();
568561
return executeOperation(
569562
this.s.db.topology,
570563
new DeleteOneOperation(this, filter, options),
@@ -609,7 +602,6 @@ export class Collection implements OperationParent {
609602
options.ignoreUndefined = this.s.options.ignoreUndefined;
610603
}
611604

612-
if (!this.s.db.topology) throw new MongoClientClosedError();
613605
return executeOperation(
614606
this.s.db.topology,
615607
new DeleteManyOperation(this, filter, options),
@@ -636,7 +628,6 @@ export class Collection implements OperationParent {
636628
if (typeof options === 'function') (callback = options), (options = {});
637629
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });
638630

639-
if (!this.s.db.topology) throw new MongoClientClosedError();
640631
return executeOperation(
641632
this.s.db.topology,
642633
new RenameOperation(this, newName, options),
@@ -661,7 +652,6 @@ export class Collection implements OperationParent {
661652
if (typeof options === 'function') (callback = options), (options = {});
662653
options = options || {};
663654

664-
if (!this.s.db.topology) throw new MongoClientClosedError();
665655
return executeOperation(
666656
this.s.db.topology,
667657
new DropCollectionOperation(this.s.db, this.collectionName, options),
@@ -697,7 +687,6 @@ export class Collection implements OperationParent {
697687
query = query || {};
698688
options = options || {};
699689

700-
if (!this.s.db.topology) throw new MongoClientClosedError();
701690
return executeOperation(
702691
this.s.db.topology,
703692
new FindOneOperation(this, query, options),
@@ -746,7 +735,6 @@ export class Collection implements OperationParent {
746735
if (typeof options === 'function') (callback = options), (options = {});
747736
options = options || {};
748737

749-
if (!this.s.db.topology) throw new MongoClientClosedError();
750738
return executeOperation(this.s.db.topology, new OptionsOperation(this, options), callback);
751739
}
752740

@@ -767,7 +755,6 @@ export class Collection implements OperationParent {
767755
if (typeof options === 'function') (callback = options), (options = {});
768756
options = options || {};
769757

770-
if (!this.s.db.topology) throw new MongoClientClosedError();
771758
return executeOperation(this.s.db.topology, new IsCappedOperation(this, options), callback);
772759
}
773760

@@ -816,7 +803,6 @@ export class Collection implements OperationParent {
816803
if (typeof options === 'function') (callback = options), (options = {});
817804
options = options || {};
818805

819-
if (!this.s.db.topology) throw new MongoClientClosedError();
820806
return executeOperation(
821807
this.s.db.topology,
822808
new CreateIndexOperation(this, this.collectionName, indexSpec, options),
@@ -873,7 +859,6 @@ export class Collection implements OperationParent {
873859
options = options ? Object.assign({}, options) : {};
874860
if (typeof options.maxTimeMS !== 'number') delete options.maxTimeMS;
875861

876-
if (!this.s.db.topology) throw new MongoClientClosedError();
877862
return executeOperation(
878863
this.s.db.topology,
879864
new CreateIndexesOperation(this, this.collectionName, indexSpecs, options),
@@ -903,7 +888,6 @@ export class Collection implements OperationParent {
903888
// Run only against primary
904889
options.readPreference = ReadPreference.primary;
905890

906-
if (!this.s.db.topology) throw new MongoClientClosedError();
907891
return executeOperation(
908892
this.s.db.topology,
909893
new DropIndexOperation(this, indexName, options),
@@ -928,7 +912,6 @@ export class Collection implements OperationParent {
928912
if (typeof options === 'function') (callback = options), (options = {});
929913
options = options ? Object.assign({}, options) : {};
930914

931-
if (!this.s.db.topology) throw new MongoClientClosedError();
932915
return executeOperation(this.s.db.topology, new DropIndexesOperation(this, options), callback);
933916
}
934917

@@ -971,7 +954,6 @@ export class Collection implements OperationParent {
971954
if (typeof options === 'function') (callback = options), (options = {});
972955
options = options || {};
973956

974-
if (!this.s.db.topology) throw new MongoClientClosedError();
975957
return executeOperation(
976958
this.s.db.topology,
977959
new IndexExistsOperation(this, indexes, options),
@@ -996,7 +978,6 @@ export class Collection implements OperationParent {
996978
if (typeof options === 'function') (callback = options), (options = {});
997979
options = options || {};
998980

999-
if (!this.s.db.topology) throw new MongoClientClosedError();
1000981
return executeOperation(
1001982
this.s.db.topology,
1002983
new IndexInformationOperation(this.s.db, this.collectionName, options),
@@ -1021,7 +1002,6 @@ export class Collection implements OperationParent {
10211002
if (typeof options === 'function') (callback = options), (options = {});
10221003
options = options || {};
10231004

1024-
if (!this.s.db.topology) throw new MongoClientClosedError();
10251005
return executeOperation(
10261006
this.s.db.topology,
10271007
new EstimatedDocumentCountOperation(this, options),
@@ -1078,8 +1058,6 @@ export class Collection implements OperationParent {
10781058

10791059
query = query || {};
10801060
options = options || {};
1081-
1082-
if (!this.s.db.topology) throw new MongoClientClosedError();
10831061
return executeOperation(
10841062
this.s.db.topology,
10851063
new CountDocumentsOperation(this, query as Document, options as CountDocumentsOptions),
@@ -1122,8 +1100,6 @@ export class Collection implements OperationParent {
11221100

11231101
query = query || {};
11241102
options = options || {};
1125-
1126-
if (!this.s.db.topology) throw new MongoClientClosedError();
11271103
return executeOperation(
11281104
this.s.db.topology,
11291105
new DistinctOperation(this, key, query as Document, options as DistinctOptions),
@@ -1148,7 +1124,6 @@ export class Collection implements OperationParent {
11481124
if (typeof options === 'function') (callback = options), (options = {});
11491125
options = options || {};
11501126

1151-
if (!this.s.db.topology) throw new MongoClientClosedError();
11521127
return executeOperation(this.s.db.topology, new IndexesOperation(this, options), callback);
11531128
}
11541129

@@ -1169,7 +1144,6 @@ export class Collection implements OperationParent {
11691144
if (typeof options === 'function') (callback = options), (options = {});
11701145
options = options || {};
11711146

1172-
if (!this.s.db.topology) throw new MongoClientClosedError();
11731147
return executeOperation(this.s.db.topology, new CollStatsOperation(this, options), callback);
11741148
}
11751149

@@ -1196,7 +1170,6 @@ export class Collection implements OperationParent {
11961170
if (typeof options === 'function') (callback = options), (options = {});
11971171
options = options || {};
11981172

1199-
if (!this.s.db.topology) throw new MongoClientClosedError();
12001173
return executeOperation(
12011174
this.s.db.topology,
12021175
new FindOneAndDeleteOperation(this, filter, options),
@@ -1234,7 +1207,6 @@ export class Collection implements OperationParent {
12341207
if (typeof options === 'function') (callback = options), (options = {});
12351208
options = options || {};
12361209

1237-
if (!this.s.db.topology) throw new MongoClientClosedError();
12381210
return executeOperation(
12391211
this.s.db.topology,
12401212
new FindOneAndReplaceOperation(this, filter, replacement, options),
@@ -1272,7 +1244,6 @@ export class Collection implements OperationParent {
12721244
if (typeof options === 'function') (callback = options), (options = {});
12731245
options = options || {};
12741246

1275-
if (!this.s.db.topology) throw new MongoClientClosedError();
12761247
return executeOperation(
12771248
this.s.db.topology,
12781249
new FindOneAndUpdateOperation(this, filter, update, options),
@@ -1383,7 +1354,6 @@ export class Collection implements OperationParent {
13831354
options.finalize = options.finalize.toString();
13841355
}
13851356

1386-
if (!this.s.db.topology) throw new MongoClientClosedError();
13871357
return executeOperation(
13881358
this.s.db.topology,
13891359
new MapReduceOperation(this, map, reduce, options),
@@ -1516,7 +1486,6 @@ export class Collection implements OperationParent {
15161486
if (typeof options === 'function') (callback = options), (options = {});
15171487
options = options || {};
15181488

1519-
if (!this.s.db.topology) throw new MongoClientClosedError();
15201489
return executeOperation(
15211490
this.s.db.topology,
15221491
new EnsureIndexOperation(this.s.db, this.collectionName, fieldOrSpec, options),
@@ -1556,8 +1525,6 @@ export class Collection implements OperationParent {
15561525

15571526
query = query || {};
15581527
options = options || {};
1559-
1560-
if (!this.s.db.topology) throw new MongoClientClosedError();
15611528
return executeOperation(
15621529
this.s.db.topology,
15631530
new EstimatedDocumentCountOperation(this, query, options),
@@ -1607,7 +1574,6 @@ export class Collection implements OperationParent {
16071574
// Add the remove option
16081575
options.remove = true;
16091576

1610-
if (!this.s.db.topology) throw new MongoClientClosedError();
16111577
return executeOperation(
16121578
this.s.db.topology,
16131579
new FindAndModifyOperation(this, query, sort as Sort, undefined, options),
@@ -1668,7 +1634,6 @@ export class Collection implements OperationParent {
16681634
// Set up the command as default
16691635
command = command == null ? true : command;
16701636

1671-
if (!this.s.db.topology) throw new MongoClientClosedError();
16721637
if (command == null) {
16731638
return executeOperation(
16741639
this.s.db.topology,
@@ -1728,7 +1693,6 @@ export class Collection implements OperationParent {
17281693
// Force read preference primary
17291694
options.readPreference = ReadPreference.primary;
17301695

1731-
if (!this.s.db.topology) throw new MongoClientClosedError();
17321696
return executeOperation(
17331697
this.s.db.topology,
17341698
new FindAndModifyOperation(this, query, sort, doc, options),

0 commit comments

Comments
 (0)