sidequest icon indicating copy to clipboard operation
sidequest copied to clipboard

mongo-backend fails to connect when config string uses a valid comma delimited host list

Open csimmons-astronomer opened this issue 11 months ago • 1 comments

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

  1. Install sidequest and mongo-backend
  2. 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",
  },
});
  1. 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;
  }

csimmons-astronomer avatar Dec 19 '25 08:12 csimmons-astronomer

:tada: This issue has been resolved in version 1.13.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

sidequest-release[bot] avatar Dec 23 '25 14:12 sidequest-release[bot]