-
-
Notifications
You must be signed in to change notification settings - Fork 18
Closed
Labels
Description
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;
}