Skip to content

Commit 5797beb

Browse files
committed
push error check to execute operation
1 parent 147e78b commit 5797beb

File tree

4 files changed

+14
-61
lines changed

4 files changed

+14
-61
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 & 33 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),
@@ -1079,7 +1059,6 @@ export class Collection implements OperationParent {
10791059
query = query || {};
10801060
options = options || {};
10811061

1082-
if (!this.s.db.topology) throw new MongoClientClosedError();
10831062
return executeOperation(
10841063
this.s.db.topology,
10851064
new CountDocumentsOperation(this, query as Document, options as CountDocumentsOptions),
@@ -1123,7 +1102,6 @@ export class Collection implements OperationParent {
11231102
query = query || {};
11241103
options = options || {};
11251104

1126-
if (!this.s.db.topology) throw new MongoClientClosedError();
11271105
return executeOperation(
11281106
this.s.db.topology,
11291107
new DistinctOperation(this, key, query as Document, options as DistinctOptions),
@@ -1148,7 +1126,6 @@ export class Collection implements OperationParent {
11481126
if (typeof options === 'function') (callback = options), (options = {});
11491127
options = options || {};
11501128

1151-
if (!this.s.db.topology) throw new MongoClientClosedError();
11521129
return executeOperation(this.s.db.topology, new IndexesOperation(this, options), callback);
11531130
}
11541131

@@ -1169,7 +1146,6 @@ export class Collection implements OperationParent {
11691146
if (typeof options === 'function') (callback = options), (options = {});
11701147
options = options || {};
11711148

1172-
if (!this.s.db.topology) throw new MongoClientClosedError();
11731149
return executeOperation(this.s.db.topology, new CollStatsOperation(this, options), callback);
11741150
}
11751151

@@ -1196,7 +1172,6 @@ export class Collection implements OperationParent {
11961172
if (typeof options === 'function') (callback = options), (options = {});
11971173
options = options || {};
11981174

1199-
if (!this.s.db.topology) throw new MongoClientClosedError();
12001175
return executeOperation(
12011176
this.s.db.topology,
12021177
new FindOneAndDeleteOperation(this, filter, options),
@@ -1234,7 +1209,6 @@ export class Collection implements OperationParent {
12341209
if (typeof options === 'function') (callback = options), (options = {});
12351210
options = options || {};
12361211

1237-
if (!this.s.db.topology) throw new MongoClientClosedError();
12381212
return executeOperation(
12391213
this.s.db.topology,
12401214
new FindOneAndReplaceOperation(this, filter, replacement, options),
@@ -1272,7 +1246,6 @@ export class Collection implements OperationParent {
12721246
if (typeof options === 'function') (callback = options), (options = {});
12731247
options = options || {};
12741248

1275-
if (!this.s.db.topology) throw new MongoClientClosedError();
12761249
return executeOperation(
12771250
this.s.db.topology,
12781251
new FindOneAndUpdateOperation(this, filter, update, options),
@@ -1383,7 +1356,6 @@ export class Collection implements OperationParent {
13831356
options.finalize = options.finalize.toString();
13841357
}
13851358

1386-
if (!this.s.db.topology) throw new MongoClientClosedError();
13871359
return executeOperation(
13881360
this.s.db.topology,
13891361
new MapReduceOperation(this, map, reduce, options),
@@ -1516,7 +1488,6 @@ export class Collection implements OperationParent {
15161488
if (typeof options === 'function') (callback = options), (options = {});
15171489
options = options || {};
15181490

1519-
if (!this.s.db.topology) throw new MongoClientClosedError();
15201491
return executeOperation(
15211492
this.s.db.topology,
15221493
new EnsureIndexOperation(this.s.db, this.collectionName, fieldOrSpec, options),
@@ -1557,7 +1528,6 @@ export class Collection implements OperationParent {
15571528
query = query || {};
15581529
options = options || {};
15591530

1560-
if (!this.s.db.topology) throw new MongoClientClosedError();
15611531
return executeOperation(
15621532
this.s.db.topology,
15631533
new EstimatedDocumentCountOperation(this, query, options),
@@ -1607,7 +1577,6 @@ export class Collection implements OperationParent {
16071577
// Add the remove option
16081578
options.remove = true;
16091579

1610-
if (!this.s.db.topology) throw new MongoClientClosedError();
16111580
return executeOperation(
16121581
this.s.db.topology,
16131582
new FindAndModifyOperation(this, query, sort as Sort, undefined, options),
@@ -1668,7 +1637,6 @@ export class Collection implements OperationParent {
16681637
// Set up the command as default
16691638
command = command == null ? true : command;
16701639

1671-
if (!this.s.db.topology) throw new MongoClientClosedError();
16721640
if (command == null) {
16731641
return executeOperation(
16741642
this.s.db.topology,
@@ -1728,7 +1696,6 @@ export class Collection implements OperationParent {
17281696
// Force read preference primary
17291697
options.readPreference = ReadPreference.primary;
17301698

1731-
if (!this.s.db.topology) throw new MongoClientClosedError();
17321699
return executeOperation(
17331700
this.s.db.topology,
17341701
new FindAndModifyOperation(this, query, sort, doc, options),

0 commit comments

Comments
 (0)