Skip to content

Commit 7a4ed82

Browse files
committed
clean up
1 parent 756b5ca commit 7a4ed82

File tree

2 files changed

+20
-53
lines changed

2 files changed

+20
-53
lines changed

src/collection.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class Collection implements OperationParent {
312312
callback?: Callback<InsertManyResult>
313313
): Promise<InsertManyResult> | void {
314314
if (typeof options === 'function') (callback = options), (options = {});
315-
options = options || {};
315+
options = options ? Object.assign({}, options) : { ordered: true };
316316

317317
return executeOperation(
318318
getTopology(this),
@@ -1305,22 +1305,12 @@ export class Collection implements OperationParent {
13051305
/** Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. */
13061306
initializeUnorderedBulkOp(options?: BulkWriteOptions): any {
13071307
options = options || {};
1308-
// Give function's options precedence over session options.
1309-
if (options.ignoreUndefined == null) {
1310-
options.ignoreUndefined = this.bsonOptions.ignoreUndefined;
1311-
}
1312-
13131308
return new UnorderedBulkOperation(this, options ?? {});
13141309
}
13151310

13161311
/** 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. */
13171312
initializeOrderedBulkOp(options?: BulkWriteOptions): any {
13181313
options = options || {};
1319-
// Give function's options precedence over session's options.
1320-
if (options.ignoreUndefined == null) {
1321-
options.ignoreUndefined = this.bsonOptions.ignoreUndefined;
1322-
}
1323-
13241314
return new OrderedBulkOperation(this, options ?? {});
13251315
}
13261316

src/utils.ts

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,57 +1082,34 @@ export function hasAtomicOperators(doc: Document | Document[]): boolean {
10821082
return keys.length > 0 && keys[0][0] === '$';
10831083
}
10841084

1085-
function resolveWriteConcern(
1086-
parent: OperationParent | undefined,
1087-
options: any
1088-
): WriteConcern | undefined {
1089-
const session = options.session;
1090-
if (session && session.inTransaction()) {
1091-
// Users cannot pass a writeConcern to operations in a transaction
1092-
return;
1093-
}
1094-
return WriteConcern.fromOptions(options) || parent?.writeConcern;
1095-
}
1096-
1097-
function resolveReadConcern(
1098-
parent: OperationParent | undefined,
1099-
options: any
1100-
): ReadConcern | undefined {
1101-
const session = options.session;
1102-
if (session && session.inTransaction()) {
1103-
// Users cannot pass a readConcern to operations in a transaction
1104-
return;
1105-
}
1106-
return ReadConcern.fromOptions(options) || parent?.readConcern;
1107-
}
1108-
1109-
function resolveReadPreference(
1110-
parent: OperationParent | undefined,
1111-
options: any
1112-
): ReadPreference | undefined {
1113-
return ReadPreference.fromOptions(options) ?? parent?.readPreference;
1114-
}
1115-
1116-
/** @internal Prioritizes options from transaction, then from options, then from parent */
1085+
/**
1086+
* Merge inherited properties from parent into options, prioritizing values from options,
1087+
* then values from parent.
1088+
* @internal
1089+
*/
11171090
export function resolveInheritedOptions<T extends CommandOperationOptions>(
11181091
parent: OperationParent | undefined,
11191092
options?: T
11201093
): T {
11211094
const result: T = Object.assign({}, options);
1095+
const session = options?.session;
11221096

1123-
const readPreference = resolveReadPreference(parent, result);
1124-
if (readPreference) {
1125-
result.readPreference = readPreference;
1126-
}
1097+
// Users cannot pass a readConcern/writeConcern to operations in a transaction
1098+
if (!session?.inTransaction()) {
1099+
const readConcern = ReadConcern.fromOptions(options) ?? parent?.readConcern;
1100+
if (readConcern) {
1101+
result.readConcern = readConcern;
1102+
}
11271103

1128-
const readConcern = resolveReadConcern(parent, result);
1129-
if (readConcern) {
1130-
result.readConcern = readConcern;
1104+
const writeConcern = WriteConcern.fromOptions(options) ?? parent?.writeConcern;
1105+
if (writeConcern) {
1106+
result.writeConcern = writeConcern;
1107+
}
11311108
}
11321109

1133-
const writeConcern = resolveWriteConcern(parent, result);
1134-
if (writeConcern) {
1135-
result.writeConcern = writeConcern;
1110+
const readPreference = ReadPreference.fromOptions(options) ?? parent?.readPreference;
1111+
if (readPreference) {
1112+
result.readPreference = readPreference;
11361113
}
11371114

11381115
const bsonOptions = resolveBSONOptions(result, parent);

0 commit comments

Comments
 (0)