Skip to content

Commit

Permalink
Fix wc spread at the mongoclient level remains
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Dec 15, 2020
1 parent 92cb64c commit e1246db
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
39 changes: 25 additions & 14 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,10 @@ export const OPTIONS = {
target: 'writeConcern',
transform({ name, options, values: [value] }): WriteConcern {
const wc = WriteConcern.fromOptions({
...options.writeConcern,
fsync: getBoolean(name, value)
writeConcern: {
...options.writeConcern,
fsync: getBoolean(name, value)
}
});
if (!wc) throw new TypeError(`Unable to make a writeConcern from fsync=${value}`);
return wc;
Expand All @@ -1216,10 +1218,11 @@ export const OPTIONS = {
j: {
target: 'writeConcern',
transform({ name, options, values: [value] }): WriteConcern {
console.warn('j is deprecated');
const wc = WriteConcern.fromOptions({
...options.writeConcern,
journal: getBoolean(name, value)
writeConcern: {
...options.writeConcern,
journal: getBoolean(name, value)
}
});
if (!wc) throw new TypeError(`Unable to make a writeConcern from journal=${value}`);
return wc;
Expand All @@ -1229,8 +1232,10 @@ export const OPTIONS = {
target: 'writeConcern',
transform({ name, options, values: [value] }): WriteConcern {
const wc = WriteConcern.fromOptions({
...options.writeConcern,
journal: getBoolean(name, value)
writeConcern: {
...options.writeConcern,
journal: getBoolean(name, value)
}
});
if (!wc) throw new TypeError(`Unable to make a writeConcern from journal=${value}`);
return wc;
Expand Down Expand Up @@ -1516,7 +1521,7 @@ export const OPTIONS = {
w: {
target: 'writeConcern',
transform({ values: [value], options }) {
return WriteConcern.fromOptions({ ...options.writeConcern, w: value as W });
return WriteConcern.fromOptions({ writeConcern: { ...options.writeConcern, w: value as W } });
}
},
waitQueueTimeoutMS: {
Expand All @@ -1528,8 +1533,10 @@ export const OPTIONS = {
transform({ values: [value], options }) {
if (isRecord(value)) {
return WriteConcern.fromOptions({
...options.writeConcern,
...value
writeConcern: {
...options.writeConcern,
...value
}
});
}
throw new MongoParseError(`WriteConcern must be an object, got ${JSON.stringify(value)}`);
Expand All @@ -1539,8 +1546,10 @@ export const OPTIONS = {
target: 'writeConcern',
transform({ values: [value], options }) {
const wc = WriteConcern.fromOptions({
...options.writeConcern,
wtimeout: getUint('wtimeout', value)
writeConcern: {
...options.writeConcern,
wtimeout: getUint('wtimeout', value)
}
});
if (wc) return wc;
throw new MongoParseError(`Cannot make WriteConcern from wtimeout`);
Expand All @@ -1550,8 +1559,10 @@ export const OPTIONS = {
target: 'writeConcern',
transform({ values: [value], options }) {
const wc = WriteConcern.fromOptions({
...options.writeConcern,
wtimeoutMS: getUint('wtimeoutMS', value)
writeConcern: {
...options.writeConcern,
wtimeoutMS: getUint('wtimeoutMS', value)
}
});
if (wc) return wc;
throw new MongoParseError(`Cannot make WriteConcern from wtimeout`);
Expand Down
16 changes: 11 additions & 5 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import { ChangeStream, ChangeStreamOptions } from './change_stream';
import { ReadPreference, ReadPreferenceModeId } from './read_preference';
import { MongoError, AnyError } from './error';
import { WriteConcern, WriteConcernOptions, W } from './write_concern';
import { WriteConcern, W, WriteConcernSettings } from './write_concern';
import { maybePromise, MongoDBNamespace, Callback, resolveOptions } from './utils';
import { deprecate } from 'util';
import { connect, validOptions } from './operations/connect';
Expand Down Expand Up @@ -134,13 +134,19 @@ export interface MongoURIOptions {
// username and password in Authority section not query string.
username?: string;
password?: string;

// remove in NODE-2704
fsync?: boolean;
w?: W;
j?: boolean;
journal?: boolean;
wtimeout?: number;
wtimeoutMS?: number;
writeConcern?: WriteConcern | WriteConcernSettings;
}

/** @public */
export interface MongoClientOptions
extends WriteConcernOptions,
MongoURIOptions,
BSONSerializeOptions {
export interface MongoClientOptions extends MongoURIOptions, BSONSerializeOptions {
/** Validate mongod server certificate against Certificate Authority */
sslValidate?: boolean;
/** SSL Certificate store binary buffer. */
Expand Down

0 comments on commit e1246db

Please sign in to comment.