Skip to content

Commit 7f61fb1

Browse files
committed
fix: 🐛 fix connection error when mongodb uses the "mongodb+srv" url scheme
1 parent fc461b9 commit 7f61fb1

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/component/connector/connection-validator.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const url = require("node:url");
2+
const util = require("node:util");
23

34

45
/**
@@ -25,13 +26,16 @@ module.exports = function validateConnectionOptions(options, { driver, defaults,
2526

2627
if(typeof options === "string") {
2728
const o = url.parse(options);
29+
const protocol = o.protocol;
2830

29-
if(o.protocol === `${driver}:`) {
31+
if(protocol === `${driver}:` || /^mongodb\+srv\:$/.test(protocol)) {
3032
for(const prop of Object.keys(defaults)) {
3133
config[prop] = o[prop] || defaults[prop];
3234
}
3335
} else {
34-
throw new TypeError(`Unable to parse ${o} as ${o.protocol} connection string!`);
36+
throw new TypeError(
37+
`Unable to parse ${util.inspect(o, { depth: 12 })} as ${protocol} connection string!`
38+
);
3539
}
3640
} else {
3741
for(const prop of Object.keys(options)) {

src/component/connector/mongoose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ module.exports = class MongooseStore {
145145

146146
debug("Mongoose connection options validated.");
147147

148-
return validatedOptions;
148+
return { ...validatedOptions, url: options?.url };
149149
}
150150
};

0 commit comments

Comments
 (0)