Skip to content

Commit

Permalink
refactor: correct type mismatch on CommandOptions for writeConcern
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Aug 22, 2020
1 parent e3cd9e6 commit 716a7f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cmap/wire_protocol/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Document, BSONSerializeOptions } from '../../bson';
import type { Server } from '../../sdam/server';
import type { Topology } from '../../sdam/topology';
import type { ReadPreferenceLike } from '../../read_preference';
import type { WriteConcernOptions, WriteConcern, W } from '../../write_concern';

/** @internal */
export interface CommandOptions extends BSONSerializeOptions {
Expand All @@ -28,6 +29,9 @@ export interface CommandOptions extends BSONSerializeOptions {
willRetryWrite?: boolean;
retryWrites?: boolean;
retrying?: boolean;

// FIXME: NODE-2781
writeConcern?: WriteConcernOptions | WriteConcern | W;
}

function isClientEncryptionEnabled(server: Server) {
Expand Down
4 changes: 3 additions & 1 deletion src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { CommandOptions } from './cmap/wire_protocol/command';
import type { MongoClientOptions } from './mongo_client';
import type { Cursor } from './cursor/cursor';
import type { CoreCursor } from './cursor/core_cursor';
import type { WriteConcern } from './write_concern';
const minWireVersionForShardedTransactions = 8;

function assertAlive(session: ClientSession, callback?: Callback): boolean {
Expand Down Expand Up @@ -720,7 +721,8 @@ function applySession(
}

// SPEC-1019: silently ignore explicit session with unacknowledged write for backwards compatibility
if (options && options.writeConcern && options.writeConcern.w === 0) {
// FIXME: NODE-2781, this check for write concern shouldn't be happening here, but instead during command construction
if (options && options.writeConcern && (options.writeConcern as WriteConcern).w === 0) {
if (session && session.explicit) {
return new MongoError('Cannot have explicit session with unacknowledged writes');
}
Expand Down

0 comments on commit 716a7f3

Please sign in to comment.