Skip to content

Commit d2b6ad8

Browse files
authored
feat(NODE-4336): deprecate old write concern options and add missing writeConcern to MongoClientOptions (#3340)
1 parent bff37aa commit d2b6ad8

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/connection_string.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ export const OPTIONS = {
11881188

11891189
throw new MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`);
11901190
}
1191-
} as OptionDescriptor,
1191+
},
11921192
wtimeout: {
11931193
deprecated: 'Please use wtimeoutMS instead',
11941194
target: 'writeConcern',

src/mongo_client.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
ns,
3434
resolveOptions
3535
} from './utils';
36-
import type { W, WriteConcern } from './write_concern';
36+
import type { W, WriteConcern, WriteConcernSettings } from './write_concern';
3737

3838
/** @public */
3939
export const ServerApiVersion = Object.freeze({
@@ -183,14 +183,28 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
183183
directConnection?: boolean;
184184
/** Instruct the driver it is connecting to a load balancer fronting a mongos like service */
185185
loadBalanced?: boolean;
186-
187-
/** The write concern w value */
186+
/**
187+
* The write concern w value
188+
* @deprecated Please use the `writeConcern` option instead
189+
*/
188190
w?: W;
189-
/** The write concern timeout */
191+
/**
192+
* The write concern timeout
193+
* @deprecated Please use the `writeConcern` option instead
194+
*/
190195
wtimeoutMS?: number;
191-
/** The journal write concern */
196+
/**
197+
* The journal write concern
198+
* @deprecated Please use the `writeConcern` option instead
199+
*/
192200
journal?: boolean;
193-
201+
/**
202+
* A MongoDB WriteConcern, which describes the level of acknowledgement
203+
* requested from MongoDB for write operations.
204+
*
205+
* @see https://docs.mongodb.com/manual/reference/write-concern/
206+
*/
207+
writeConcern?: WriteConcern | WriteConcernSettings;
194208
/** Validate mongod server certificate against Certificate Authority */
195209
sslValidate?: boolean;
196210
/** SSL Certificate file path. */

test/types/mongodb.test-d.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Document } from 'bson';
22
import { expectDeprecated, expectError, expectNotDeprecated, expectType } from 'tsd';
33

4-
import { Db, WithId } from '../../src';
4+
import { Db, WithId, WriteConcern, WriteConcernSettings } from '../../src';
55
import * as MongoDBDriver from '../../src';
66
import type { ChangeStreamDocument } from '../../src/change_stream';
77
import { Collection } from '../../src/collection';
@@ -23,6 +23,13 @@ expectDeprecated(Db.prototype.unref);
2323
expectDeprecated(MongoDBDriver.ObjectID);
2424
expectNotDeprecated(MongoDBDriver.ObjectId);
2525

26+
declare const options: MongoDBDriver.MongoClientOptions;
27+
expectDeprecated(options.w);
28+
expectDeprecated(options.journal);
29+
expectDeprecated(options.wtimeoutMS);
30+
expectNotDeprecated(options.writeConcern);
31+
expectType<WriteConcernSettings | WriteConcern | undefined>(options.writeConcern);
32+
2633
interface TSchema extends Document {
2734
name: string;
2835
}

0 commit comments

Comments
 (0)