Skip to content

Commit a4d90a6

Browse files
committed
respond to comments
1 parent 8f5fb8b commit a4d90a6

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

src/collection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,13 +1309,11 @@ export class Collection implements OperationParent {
13091309

13101310
/** Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. */
13111311
initializeUnorderedBulkOp(options?: BulkWriteOptions): any {
1312-
options = options || {};
13131312
return new UnorderedBulkOperation(this, options ?? {});
13141313
}
13151314

13161315
/** Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types. */
13171316
initializeOrderedBulkOp(options?: BulkWriteOptions): any {
1318-
options = options || {};
13191317
return new OrderedBulkOperation(this, options ?? {});
13201318
}
13211319

src/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class Db implements OperationParent {
284284
// Intentionally, we do not inherit options from parent for this operation.
285285
return executeOperation(
286286
getTopology(this),
287-
new RunCommandOperation(this, command, options || {}),
287+
new RunCommandOperation(this, command, options ?? {}),
288288
callback
289289
);
290290
}
@@ -567,7 +567,7 @@ export class Db implements OperationParent {
567567
// Intentionally, we do not inherit options from parent for this operation.
568568
return executeOperation(
569569
getTopology(this),
570-
new RunAdminCommandOperation(this, command, options || {}),
570+
new RunAdminCommandOperation(this, command, options ?? {}),
571571
callback
572572
);
573573
}

src/operations/command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ export abstract class CommandOperation<
7373
: new MongoDBNamespace('admin', '$cmd');
7474
}
7575

76-
const readPref = ReadPreference.fromOptions(options) ?? ReadPreference.primary;
7776
this.readPreference = this.hasAspect(Aspect.WRITE_OPERATION)
7877
? ReadPreference.primary
79-
: readPref;
78+
: ReadPreference.fromOptions(options) ?? ReadPreference.primary;
8079
this.readConcern = ReadConcern.fromOptions(options);
8180
this.writeConcern = WriteConcern.fromOptions(options);
8281
this.bsonOptions = resolveBSONOptions(options);

src/utils.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ReadConcern } from './read_concern';
1414
import type { Connection } from './cmap/connection';
1515
import { readFileSync } from 'fs';
1616
import { resolve } from 'path';
17-
import { Document, resolveBSONOptions } from './bson';
17+
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
1818
import type { IndexSpecification, IndexDirection } from './operations/indexes';
1919
import type { MongoClient } from './mongo_client';
2020
import type { Cursor } from './cursor/cursor';
@@ -1091,10 +1091,10 @@ export function resolveOptions<T extends CommandOperationOptions>(
10911091
parent: OperationParent | undefined,
10921092
options?: T
10931093
): T {
1094-
const result: T = Object.assign({}, options);
1095-
const session = options?.session;
1094+
const result: T = Object.assign({}, options, resolveBSONOptions(options, parent));
10961095

10971096
// Users cannot pass a readConcern/writeConcern to operations in a transaction
1097+
const session = options?.session;
10981098
if (!session?.inTransaction()) {
10991099
const readConcern = ReadConcern.fromOptions(options) ?? parent?.readConcern;
11001100
if (readConcern) {
@@ -1112,7 +1112,5 @@ export function resolveOptions<T extends CommandOperationOptions>(
11121112
result.readPreference = readPreference;
11131113
}
11141114

1115-
const bsonOptions = resolveBSONOptions(result, parent);
1116-
1117-
return { ...result, ...bsonOptions };
1115+
return result;
11181116
}

0 commit comments

Comments
 (0)