diff --git a/src/connection_string.ts b/src/connection_string.ts index 5b3d494a77..4aefe33d6a 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1188,7 +1188,7 @@ export const OPTIONS = { throw new MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`); } - } as OptionDescriptor, + }, wtimeout: { deprecated: 'Please use wtimeoutMS instead', target: 'writeConcern', diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 5c152e311d..45f8a240f9 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -33,7 +33,7 @@ import { ns, resolveOptions } from './utils'; -import type { W, WriteConcern } from './write_concern'; +import type { W, WriteConcern, WriteConcernSettings } from './write_concern'; /** @public */ export const ServerApiVersion = Object.freeze({ @@ -183,14 +183,28 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC directConnection?: boolean; /** Instruct the driver it is connecting to a load balancer fronting a mongos like service */ loadBalanced?: boolean; - - /** The write concern w value */ + /** + * The write concern w value + * @deprecated Please use the `writeConcern` option instead + */ w?: W; - /** The write concern timeout */ + /** + * The write concern timeout + * @deprecated Please use the `writeConcern` option instead + */ wtimeoutMS?: number; - /** The journal write concern */ + /** + * The journal write concern + * @deprecated Please use the `writeConcern` option instead + */ journal?: boolean; - + /** + * A MongoDB WriteConcern, which describes the level of acknowledgement + * requested from MongoDB for write operations. + * + * @see https://docs.mongodb.com/manual/reference/write-concern/ + */ + writeConcern?: WriteConcern | WriteConcernSettings; /** Validate mongod server certificate against Certificate Authority */ sslValidate?: boolean; /** SSL Certificate file path. */ diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 024482fb50..75c17ab3b0 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -1,7 +1,7 @@ import type { Document } from 'bson'; import { expectDeprecated, expectError, expectNotDeprecated, expectType } from 'tsd'; -import { Db, WithId } from '../../src'; +import { Db, WithId, WriteConcern, WriteConcernSettings } from '../../src'; import * as MongoDBDriver from '../../src'; import type { ChangeStreamDocument } from '../../src/change_stream'; import { Collection } from '../../src/collection'; @@ -23,6 +23,13 @@ expectDeprecated(Db.prototype.unref); expectDeprecated(MongoDBDriver.ObjectID); expectNotDeprecated(MongoDBDriver.ObjectId); +declare const options: MongoDBDriver.MongoClientOptions; +expectDeprecated(options.w); +expectDeprecated(options.journal); +expectDeprecated(options.wtimeoutMS); +expectNotDeprecated(options.writeConcern); +expectType(options.writeConcern); + interface TSchema extends Document { name: string; }