Skip to content

Commit fabf2e5

Browse files
fix: add back read concern application logic
1 parent dd49bc5 commit fabf2e5

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

etc/notes/CHANGES_5.0.0.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ to migrate code that uses `Collection.mapReduce` to use the aggregation pipeline
2525
If the `mapReduce` command must be used, the `Db.command()` helper can be used to run the raw
2626
`mapReduce` command.
2727

28+
```typescript
29+
const command = {
30+
mapReduce: 'my-collection',
31+
map: 'function() { emit(this.user_id, 1); }',
32+
reduce: 'function(k,vals) { return 1; }',
33+
out: 'inline',
34+
readConcern: 'majority'
35+
}
36+
37+
await db.command(command);
38+
```
39+
40+
**Note** When using the `Db.command()` helper, all `mapReduce` options should be specified
41+
on the raw command object and should not be passed through the options object.
42+
2843
### `AddUserOptions.digestPassword` removed
2944

3045
The `digestPassword` option has been removed from the add user helper.

src/sessions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ export function applySession(
10071007
if (
10081008
session.supports.causalConsistency &&
10091009
session.operationTime &&
1010-
commandSupportsReadConcern(command)
1010+
commandSupportsReadConcern(command, options)
10111011
) {
10121012
command.readConcern = command.readConcern || {};
10131013
Object.assign(command.readConcern, { afterClusterTime: session.operationTime });

src/utils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,23 @@ export function shuffle<T>(sequence: Iterable<T>, limit = 0): Array<T> {
13261326
return limit % items.length === 0 ? items : items.slice(lowerBound);
13271327
}
13281328

1329-
// TODO: this should be codified in command construction
1329+
// TODO(NODE-4936): read concern eligibility for commands should be codified in command construction
13301330
// @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#read-concern
1331-
export function commandSupportsReadConcern(command: Document): boolean {
1332-
return command.aggregate || command.count || command.distinct || command.find || command.geoNear;
1331+
export function commandSupportsReadConcern(command: Document, options?: Document): boolean {
1332+
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
1333+
return true;
1334+
}
1335+
1336+
if (
1337+
command.mapReduce &&
1338+
options &&
1339+
options.out &&
1340+
(options.out.inline === 1 || options.out === 'inline')
1341+
) {
1342+
return true;
1343+
}
1344+
1345+
return false;
13331346
}
13341347

13351348
/** A utility function to get the instance of mongodb-client-encryption, if it exists. */

0 commit comments

Comments
 (0)