Skip to content

Commit c08060d

Browse files
nbbeekendurran
andauthored
feat(NODE-5444)!: emit deprecation warning for useNewUrlParser and useUnifiedTopology (#3792)
Co-authored-by: Durran Jordan <[email protected]>
1 parent 844aa52 commit c08060d

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

Diff for: src/connection_string.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,17 @@ export const OPTIONS = {
12231223
pfx: { type: 'any' },
12241224
secureProtocol: { type: 'any' },
12251225
index: { type: 'any' },
1226-
// Legacy Options, these are unused but left here to avoid errors with CSFLE lib
1227-
useNewUrlParser: { type: 'boolean' } as OptionDescriptor,
1228-
useUnifiedTopology: { type: 'boolean' } as OptionDescriptor,
1226+
// Legacy options from v3 era
1227+
useNewUrlParser: {
1228+
type: 'boolean',
1229+
deprecated:
1230+
'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version'
1231+
} as OptionDescriptor,
1232+
useUnifiedTopology: {
1233+
type: 'boolean',
1234+
deprecated:
1235+
'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version'
1236+
} as OptionDescriptor,
12291237
// MongoLogger
12301238
// TODO(NODE-4849): Tighten the type of mongodbLogPath
12311239
mongodbLogPath: { type: 'any' }

Diff for: test/unit/connection_string.test.ts

+39
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { once } from 'node:events';
2+
import * as process from 'node:process';
3+
14
import { expect } from 'chai';
25
import * as dns from 'dns';
36
import * as sinon from 'sinon';
@@ -761,4 +764,40 @@ describe('Connection String', function () {
761764
expect(() => new MongoClient('mango://localhost:23')).to.throw(/Invalid scheme/i);
762765
expect(() => new MongoClient('mango+srv://localhost:23')).to.throw(/Invalid scheme/i);
763766
});
767+
768+
describe('when deprecated options are used', () => {
769+
it('useNewUrlParser emits a warning', async () => {
770+
let willBeWarning = once(process, 'warning');
771+
parseOptions('mongodb://host?useNewUrlParser=true');
772+
let [warning] = await willBeWarning;
773+
expect(warning)
774+
.to.have.property('message')
775+
.that.matches(/useNewUrlParser has no effect/);
776+
777+
willBeWarning = once(process, 'warning');
778+
//@ts-expect-error: using unsupported option on purpose
779+
parseOptions('mongodb://host', { useNewUrlParser: true });
780+
[warning] = await willBeWarning;
781+
expect(warning)
782+
.to.have.property('message')
783+
.that.matches(/useNewUrlParser has no effect/);
784+
});
785+
786+
it('useUnifiedTopology emits a warning', async () => {
787+
let willBeWarning = once(process, 'warning');
788+
parseOptions('mongodb://host?useUnifiedTopology=true');
789+
let [warning] = await willBeWarning;
790+
expect(warning)
791+
.to.have.property('message')
792+
.that.matches(/useUnifiedTopology has no effect/);
793+
794+
willBeWarning = once(process, 'warning');
795+
//@ts-expect-error: using unsupported option on purpose
796+
parseOptions('mongodb://host', { useUnifiedTopology: true });
797+
[warning] = await willBeWarning;
798+
expect(warning)
799+
.to.have.property('message')
800+
.that.matches(/useUnifiedTopology has no effect/);
801+
});
802+
});
764803
});

0 commit comments

Comments
 (0)