Skip to content

Commit 80eec57

Browse files
committed
bug fixes for mapReduce and inheriting with transactions
1 parent ce026fc commit 80eec57

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

src/collection.ts

Lines changed: 1 addition & 1 deletion
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 = resolveInheritedOptions(this, options ?? { ordered: true });
315+
options = options || {};
316316

317317
return executeOperation(
318318
getTopology(this),

src/operations/map_reduce.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { ObjectId } from '../bson';
1717

1818
const exclusionList = [
1919
'readPreference',
20+
'readConcern',
2021
'session',
2122
'bypassDocumentValidation',
2223
'w',

src/read_preference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export class ReadPreference {
141141
*/
142142
static fromOptions(options?: ReadPreferenceFromOptions): ReadPreference | undefined {
143143
if (!options) return;
144-
const readPreference = options.readPreference;
144+
const readPreference =
145+
options.readPreference ?? options.session?.transaction.options.readPreference;
145146
const readPreferenceTags = options.readPreferenceTags;
146147

147148
if (readPreference == null) {

src/utils.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,9 @@ function resolveWriteConcern(
10871087
options: any
10881088
): WriteConcern | undefined {
10891089
const session = options.session;
1090-
if (
1091-
session &&
1092-
session.inTransaction() &&
1093-
session.transaction.options.writeConcern !== 'undefined'
1094-
) {
1095-
return session.transaction.options.writeConcern;
1090+
if (session && session.inTransaction()) {
1091+
// Users cannot pass a writeConcern to operations in a transaction
1092+
return;
10961093
}
10971094
return WriteConcern.fromOptions(options) || parent?.writeConcern;
10981095
}
@@ -1102,12 +1099,9 @@ function resolveReadConcern(
11021099
options: any
11031100
): ReadConcern | undefined {
11041101
const session = options.session;
1105-
if (
1106-
session &&
1107-
session.inTransaction() &&
1108-
session.transaction.options.readConcern !== 'undefined'
1109-
) {
1110-
return session.transaction.options.readConcern;
1102+
if (session && session.inTransaction()) {
1103+
// Users cannot pass a readConcern to operations in a transaction
1104+
return;
11111105
}
11121106
return ReadConcern.fromOptions(options) || parent?.readConcern;
11131107
}
@@ -1116,15 +1110,7 @@ function resolveReadPreference(
11161110
parent: OperationParent | undefined,
11171111
options: any
11181112
): ReadPreference | undefined {
1119-
const session = options.session;
1120-
if (
1121-
session &&
1122-
session.inTransaction() &&
1123-
session.transaction.options.readPreference !== 'undefined'
1124-
) {
1125-
return session.transaction.options.readPreference;
1126-
}
1127-
return ReadPreference.fromOptions(options) || parent?.readPreference;
1113+
return ReadPreference.fromOptions(options) ?? parent?.readPreference;
11281114
}
11291115

11301116
/** @internal Prioritizes options from transaction, then from options, then from parent */

0 commit comments

Comments
 (0)