diff --git a/src/connection_string.ts b/src/connection_string.ts index 0d8e511eb0e..5b3da011ed4 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1223,9 +1223,17 @@ export const OPTIONS = { pfx: { type: 'any' }, secureProtocol: { type: 'any' }, index: { type: 'any' }, - // Legacy Options, these are unused but left here to avoid errors with CSFLE lib - useNewUrlParser: { type: 'boolean' } as OptionDescriptor, - useUnifiedTopology: { type: 'boolean' } as OptionDescriptor, + // Legacy options from v3 era + useNewUrlParser: { + type: 'boolean', + deprecated: + 'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' + } as OptionDescriptor, + useUnifiedTopology: { + type: 'boolean', + deprecated: + 'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' + } as OptionDescriptor, // MongoLogger // TODO(NODE-4849): Tighten the type of mongodbLogPath mongodbLogPath: { type: 'any' } diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index 0439d49984c..54c4733aa2f 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -1,3 +1,6 @@ +import { once } from 'node:events'; +import * as process from 'node:process'; + import { expect } from 'chai'; import * as dns from 'dns'; import * as sinon from 'sinon'; @@ -761,4 +764,40 @@ describe('Connection String', function () { expect(() => new MongoClient('mango://localhost:23')).to.throw(/Invalid scheme/i); expect(() => new MongoClient('mango+srv://localhost:23')).to.throw(/Invalid scheme/i); }); + + describe('when deprecated options are used', () => { + it('useNewUrlParser emits a warning', async () => { + let willBeWarning = once(process, 'warning'); + parseOptions('mongodb://host?useNewUrlParser=true'); + let [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useNewUrlParser has no effect/); + + willBeWarning = once(process, 'warning'); + //@ts-expect-error: using unsupported option on purpose + parseOptions('mongodb://host', { useNewUrlParser: true }); + [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useNewUrlParser has no effect/); + }); + + it('useUnifiedTopology emits a warning', async () => { + let willBeWarning = once(process, 'warning'); + parseOptions('mongodb://host?useUnifiedTopology=true'); + let [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useUnifiedTopology has no effect/); + + willBeWarning = once(process, 'warning'); + //@ts-expect-error: using unsupported option on purpose + parseOptions('mongodb://host', { useUnifiedTopology: true }); + [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useUnifiedTopology has no effect/); + }); + }); });