Skip to content

Commit 328695b

Browse files
committed
options || => options ??
1 parent 713b92d commit 328695b

40 files changed

+72
-68
lines changed

src/admin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Admin {
104104
callback?: Callback<Document>
105105
): Promise<Document> | void {
106106
if (typeof options === 'function') (callback = options), (options = {});
107-
options = options || {};
107+
options = options ?? {};
108108
return this.command({ buildinfo: 1 }, options, callback as Callback<Document>);
109109
}
110110

@@ -123,7 +123,7 @@ export class Admin {
123123
callback?: Callback<Document>
124124
): Promise<Document> | void {
125125
if (typeof options === 'function') (callback = options), (options = {});
126-
options = options || {};
126+
options = options ?? {};
127127
return this.command({ buildinfo: 1 }, options, callback as Callback<Document>);
128128
}
129129

@@ -142,7 +142,7 @@ export class Admin {
142142
callback?: Callback<Document>
143143
): Promise<Document> | void {
144144
if (typeof options === 'function') (callback = options), (options = {});
145-
options = options || {};
145+
options = options ?? {};
146146
return this.command({ serverStatus: 1 }, options, callback as Callback<Document>);
147147
}
148148

@@ -161,7 +161,7 @@ export class Admin {
161161
callback?: Callback<Document>
162162
): Promise<Document> | void {
163163
if (typeof options === 'function') (callback = options), (options = {});
164-
options = options || {};
164+
options = options ?? {};
165165
return this.command({ ping: 1 }, options, callback as Callback<Document>);
166166
}
167167

@@ -260,7 +260,7 @@ export class Admin {
260260
callback?: Callback<Document>
261261
): Promise<Document> | void {
262262
if (typeof options === 'function') (callback = options), (options = {});
263-
options = options || {};
263+
options = options ?? {};
264264

265265
return executeOperation(
266266
getTopology(this.s.db),
@@ -284,7 +284,7 @@ export class Admin {
284284
callback?: Callback<ListDatabasesResult>
285285
): Promise<ListDatabasesResult> | void {
286286
if (typeof options === 'function') (callback = options), (options = {});
287-
options = options || {};
287+
options = options ?? {};
288288

289289
return executeOperation(
290290
getTopology(this.s.db),
@@ -308,7 +308,7 @@ export class Admin {
308308
callback?: Callback<Document>
309309
): Promise<Document> | void {
310310
if (typeof options === 'function') (callback = options), (options = {});
311-
options = options || {};
311+
options = options ?? {};
312312
return this.command({ replSetGetStatus: 1 }, options, callback as Callback<Document>);
313313
}
314314
}

src/bulk/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ export abstract class BulkOperationBase {
11991199
/** An internal helper method. Do not invoke directly. Will be going away in the future */
12001200
execute(options?: BulkWriteOptions, callback?: Callback<BulkWriteResult>): Promise<void> | void {
12011201
if (typeof options === 'function') (callback = options), (options = {});
1202-
options = options || {};
1202+
options = options ?? {};
12031203

12041204
const writeConcern = WriteConcern.fromOptions(options);
12051205
if (writeConcern) {

src/cmap/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ export class Response {
538538
parse(options: OpResponseOptions): void {
539539
// Don't parse again if not needed
540540
if (this.parsed) return;
541-
options = options || {};
541+
options = options ?? {};
542542

543543
// Allow the return of raw documents instead of parsing
544544
const raw = options.raw || false;
@@ -666,7 +666,7 @@ export class Msg {
666666
}
667667

668668
// Ensure empty options
669-
this.options = options || {};
669+
this.options = options ?? {};
670670

671671
// Additional options
672672
this.requestId = options.requestId ? options.requestId : Msg.getRequestId();
@@ -806,7 +806,7 @@ export class BinMsg {
806806
parse(options: OpResponseOptions): void {
807807
// Don't parse again if not needed
808808
if (this.parsed) return;
809-
options = options || {};
809+
options = options ?? {};
810810

811811
this.index = 4;
812812
// Allow the return of raw documents instead of parsing

src/cmap/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function write(
376376
callback = options;
377377
}
378378

379-
options = options || {};
379+
options = options ?? {};
380380
const operationDescription: OperationDescription = {
381381
requestId: command.requestId,
382382
cb: callback,

src/cmap/wire_protocol/get_more.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function getMore(
2121
options: GetMoreOptions,
2222
callback: Callback<Document>
2323
): void {
24-
options = options || {};
24+
options = options ?? {};
2525

2626
const fullResult = typeof options.fullResult === 'boolean' ? options.fullResult : false;
2727
const wireVersion = maxWireVersion(server);

src/cmap/wire_protocol/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function query(
2828
options: QueryOptions,
2929
callback: Callback
3030
): void {
31-
options = options || {};
31+
options = options ?? {};
3232

3333
const isExplain = typeof findCommand.$explain !== 'undefined';
3434
const readPreference = options.readPreference ?? ReadPreference.primary;

src/cmap/wire_protocol/write_command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function writeCommand(
4141
options = {};
4242
}
4343

44-
options = options || {};
44+
options = options ?? {};
4545
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
4646
const writeConcern = options.writeConcern;
4747
let writeCommand: Document = {};

src/collection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ export class Collection implements OperationParent {
585585
callback?: Callback<boolean>
586586
): Promise<boolean> | void {
587587
if (typeof options === 'function') (callback = options), (options = {});
588-
options = options || {};
588+
options = options ?? {};
589589

590590
return executeOperation(
591591
getTopology(this),
@@ -1089,7 +1089,7 @@ export class Collection implements OperationParent {
10891089
callback?: Callback<Document>
10901090
): Promise<Document> | void {
10911091
if (typeof options === 'function') (callback = options), (options = {});
1092-
options = options || {};
1092+
options = options ?? {};
10931093

10941094
return executeOperation(getTopology(this), new CollStatsOperation(this, options), callback);
10951095
}
@@ -1232,7 +1232,7 @@ export class Collection implements OperationParent {
12321232
watch(pipeline?: Document[]): ChangeStream;
12331233
watch(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream {
12341234
pipeline = pipeline || [];
1235-
options = options || {};
1235+
options = options ?? {};
12361236

12371237
// Allow optionally not specifying a pipeline
12381238
if (!Array.isArray(pipeline)) {
@@ -1365,7 +1365,7 @@ export class Collection implements OperationParent {
13651365
callback: Callback<Document>
13661366
): Promise<UpdateResult> | void {
13671367
if (typeof options === 'function') (callback = options), (options = {});
1368-
options = options || {};
1368+
options = options ?? {};
13691369

13701370
return this.updateMany(selector, update, options, callback);
13711371
}
@@ -1384,7 +1384,7 @@ export class Collection implements OperationParent {
13841384
callback: Callback
13851385
): Promise<DeleteResult> | void {
13861386
if (typeof options === 'function') (callback = options), (options = {});
1387-
options = options || {};
1387+
options = options ?? {};
13881388

13891389
return this.deleteMany(selector, options, callback);
13901390
}

src/cursor/abstract_cursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export abstract class AbstractCursor extends EventEmitter {
318318
close(options: CursorCloseOptions, callback: Callback): void;
319319
close(options?: CursorCloseOptions | Callback, callback?: Callback): Promise<void> | void {
320320
if (typeof options === 'function') (callback = options), (options = {});
321-
options = options || {};
321+
options = options ?? {};
322322

323323
const needsToEmitClosed = !this[kClosed];
324324
this[kClosed] = true;

src/cursor/find_cursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class FindCursor extends AbstractCursor {
120120
}
121121

122122
if (typeof options === 'function') (callback = options), (options = {});
123-
options = options || {};
123+
options = options ?? {};
124124

125125
return executeOperation(
126126
this.topology,

src/db.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class Db implements OperationParent {
154154
* @param options - Optional settings for Db construction
155155
*/
156156
constructor(client: MongoClient, databaseName: string, options?: DbOptions) {
157-
options = options || {};
157+
options = options ?? {};
158158
emitDeprecatedOptionWarning(options, ['promiseLibrary']);
159159

160160
// Filter the options
@@ -781,7 +781,7 @@ export class Db implements OperationParent {
781781
watch(pipeline?: Document[]): ChangeStream;
782782
watch(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream {
783783
pipeline = pipeline || [];
784-
options = options || {};
784+
options = options ?? {};
785785

786786
// Allow optionally not specifying a pipeline
787787
if (!Array.isArray(pipeline)) {
@@ -887,7 +887,7 @@ export class Db implements OperationParent {
887887
callback?: Callback<Document[]>
888888
): Promise<Document[]> | void {
889889
if (typeof options === 'function') (callback = options), (options = {});
890-
options = options || {};
890+
options = options ?? {};
891891

892892
const cursor = this.collection('system.profile').find({}, options);
893893
return callback ? cursor.toArray(callback) : cursor.toArray();

src/gridfs-stream/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class GridFSBucket extends EventEmitter {
142142
/** Convenience wrapper around find on the files collection */
143143
find(filter: Document, options?: FindOptions): FindCursor {
144144
filter = filter || {};
145-
options = options || {};
145+
options = options ?? {};
146146
return this.s._filesCollection.find(filter, options);
147147
}
148148

src/gridfs-stream/upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class GridFSBucketWriteStream extends Writable {
8383
constructor(bucket: GridFSBucket, filename: string, options?: GridFSBucketWriteStreamOptions) {
8484
super();
8585

86-
options = options || {};
86+
options = options ?? {};
8787
this.bucket = bucket;
8888
this.chunks = bucket.s._chunksCollection;
8989
this.filename = filename;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export type {
222222
MapReduceOptions,
223223
FinalizeFunction
224224
} from './operations/map_reduce';
225-
export type { Hint, OperationOptions, AbstractOperation as OperationBase } from './operations/operation';
225+
export type { Hint, OperationOptions, AbstractOperation } from './operations/operation';
226226
export type { ProfilingLevelOptions } from './operations/profiling_level';
227227
export type { RemoveUserOptions } from './operations/remove_user';
228228
export type { RenameOptions } from './operations/rename';

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Logger {
4242
* @param options - Optional logging settings
4343
*/
4444
constructor(className: string, options?: LoggerOptions) {
45-
options = options || {};
45+
options = options ?? {};
4646

4747
// Current reference
4848
this.className = className;

src/mongo_client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export class MongoClient extends EventEmitter implements OperationParent {
386386
db(dbName: string): Db;
387387
db(dbName: string, options: DbOptions & { returnNonCachedInstance?: boolean }): Db;
388388
db(dbName: string, options?: DbOptions & { returnNonCachedInstance?: boolean }): Db {
389-
options = options || {};
389+
options = options ?? {};
390390

391391
// Default to db from connection string if not provided
392392
if (!dbName && this.s.options?.dbName) {
@@ -437,7 +437,7 @@ export class MongoClient extends EventEmitter implements OperationParent {
437437
callback?: Callback<MongoClient>
438438
): Promise<MongoClient> | void {
439439
if (typeof options === 'function') (callback = options), (options = {});
440-
options = options || {};
440+
options = options ?? {};
441441

442442
// Create client
443443
const mongoClient = new MongoClient(url, options);
@@ -527,7 +527,7 @@ export class MongoClient extends EventEmitter implements OperationParent {
527527
watch(pipeline?: Document[]): ChangeStream;
528528
watch(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream {
529529
pipeline = pipeline || [];
530-
options = options || {};
530+
options = options ?? {};
531531

532532
// Allow optionally not specifying a pipeline
533533
if (!Array.isArray(pipeline)) {

src/operations/add_user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AddUserOperation extends CommandOperation<Document> {
3737
this.db = db;
3838
this.username = username;
3939
this.password = password;
40-
this.options = options || {};
40+
this.options = options ?? {};
4141
}
4242

4343
execute(server: Server, session: ClientSession, callback: Callback<Document>): void {

src/operations/aggregate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
4444
constructor(parent: OperationParent, pipeline: Document[], options?: AggregateOptions) {
4545
super(parent, options);
4646

47-
this.options = options || {};
47+
this.options = options ?? {};
4848
this.target =
4949
parent.s.namespace && parent.s.namespace.collection
5050
? parent.s.namespace.collection

src/operations/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
5959

6060
constructor(parent?: OperationParent, options?: CommandOperationOptions) {
6161
super(options);
62-
this.options = options || {};
62+
this.options = options ?? {};
6363

6464
// NOTE: this was explicitly added for the add/remove user operations, it's likely
6565
// something we'd want to reconsider. Perhaps those commands can use `Admin`

src/operations/common_functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function removeDocuments(
134134
}
135135

136136
// Create an empty options object if the provided one is null
137-
options = options || {};
137+
options = options ?? {};
138138

139139
// Final options for retryable writes
140140
let finalOptions = Object.assign({}, options);

src/operations/distinct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class DistinctOperation extends CommandOperation<Document[]> {
3333
constructor(collection: Collection, key: string, query: Document, options?: DistinctOptions) {
3434
super(collection, options);
3535

36-
this.options = options || {};
36+
this.options = options ?? {};
3737
this.collection = collection;
3838
this.key = key;
3939
this.query = query;

src/operations/eval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class EvalOperation extends CommandOperation<Document> {
2727
) {
2828
super(db, options);
2929

30-
this.options = options || {};
30+
this.options = options ?? {};
3131
this.code = code;
3232
this.parameters = parameters;
3333
// force primary read preference

src/operations/execute_operation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ function executeWithServerSelection(topology: Topology, operation: any, callback
174174
});
175175
}
176176

177-
if (readPreference && !readPreference.equals(ReadPreference.primary) && session.inTransaction()) {
177+
if (
178+
readPreference &&
179+
!readPreference.equals(ReadPreference.primary) &&
180+
session &&
181+
session.inTransaction()
182+
) {
178183
callback(
179184
new MongoError(
180185
`Read preference in a transaction must be primary, not: ${readPreference.mode}`

src/operations/find_and_modify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
5656
options?: FindAndModifyOptions
5757
) {
5858
super(collection, options);
59-
this.options = options || {};
59+
this.options = options ?? {};
6060

6161
// force primary read preference
6262
this.readPreference = ReadPreference.primary;

0 commit comments

Comments
 (0)