sidequest
sidequest copied to clipboard
mongo-backend fails to connect when config string uses a valid comma delimited host list
Problem
Using "URL" to parse mongo connection URI for comma separated node list, which isn't supported natively by URL https://github.com/sidequestjs/sidequest/blob/master/packages/backends/mongo/src/mongo-backend.ts#L52
Recreation
Invalid Mongo Backend Config
- Install sidequest and mongo-backend
- Attempt to connect to a multi-node replicaset (example config string taken directly from mongo-backend README here: https://github.com/sidequestjs/sidequest/blob/master/packages/backends/mongo/README.md?plain=1#L77)
import { Sidequest } from "sidequest";
await Sidequest.start({
backend: {
driver: "@sidequest/mongo-backend",
config: "mongodb://mongo1:27017,mongo2:27017,mongo3:27017/myapp?replicaSet=rs0",
},
});
- Observe
TypeError: Invalid URL
Most Basic Example of URL parse failure
new URL('mongodb://mongo1:27017,mongo2:27017,mongo3:27017/myapp?replicaSet=rs0')
Proposed Solution
- https://github.com/sidequestjs/sidequest/blob/master/packages/backends/mongo/src/mongo-backend.ts#L51C3-L60C4 Don't parse the URL at all, and remove the unnecessary parameter to this.client.db since the default database for the mongo driver is already "test" if not defined in the connection URI.
constructor(mongoUrl: string) {
this.client = new MongoClient(mongoUrl, { ignoreUndefined: true });
this.db = this.client.db();
this.jobs = this.db.collection<JobData>("sidequest_jobs");
this.queues = this.db.collection<QueueConfig>("sidequest_queues");
this.counters = this.db.collection("sidequest_counters");
this._connected = false;
}
:tada: This issue has been resolved in version 1.13.1 :tada:
The release is available on:
v1.13.1- GitHub release
Your semantic-release bot :package::rocket: