-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue Description
I like to test failed over with mongodb replica set and found It's not working then I try to console log a value of "connectionString" at method "buildConnectionUrl" and found this result below.
My example connection string
mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb?replicaSet=testreplicaset
Result console log of connectionString
mongodb://test-primary.example.com:27017/testdb
As above secondary domain wasn't include in connectionString and I found some code in "parseConnectionUrl" split text like
const [host, port] = hostAndPort.split(":");
That's mean It's split host and port like standalone machine and another host was split out to no where.
In addition in "parseConnectionUrl" I found this;
// remove mongodb query params
if (afterBase && afterBase.indexOf("?") !== -1) {
afterBase = afterBase.substr(0, afterBase.indexOf("?"));
}
It's remove query params and that's why ReplicaSet Name was gone.
Last notice, method "buildConnectionUrl" was return format string like
return `${schemaUrlPart}://${credentialsUrlPart}${options.host || "127.0.0.1"}${portUrlPart}/${options.database || ""}`;
It's definitely not support replica set connection string for sure.
Expected Behavior
My example connection string
mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb?replicaSet=testreplicaset
Expected result console log of connectionString at method buildConnectionUrl
mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb
Actual Behavior
My example connection string
mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb?replicaSet=testreplicaset
Actual result console log of connectionString at method buildConnectionUrl
mongodb://test-primary.example.com:27017/testdb
Steps to Reproduce
- Create connection typescript source code
createConnection({
name: 'mongoConnection',
type: 'mongodb',
url: `mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb?replicaSet=testreplicaset`,
entities: [ExampleEntity]
})
PS. My use case can't separate replicaSet like this
createConnection({
name: 'mongoConnection',
type: 'mongodb',
url: `mongodb://test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb`,
replicaSet: 'testreplicaset',
entities: [ExampleEntity]
})
My ancient code fixed me to do like this haha but I think It should flexible to do both way.
2. console log of connectionString at method buildConnectionUrl
My Environment
| Dependency | Version |
|---|---|
| Operating System | Ubuntu 18.04 |
| Node.js version | v12.14.1 |
| Typescript version | ~v3.8.0 |
| TypeORM version | v0.2.31 |
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don't know how to start. I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.