Skip to content

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

@csimmons-astronomer

Description

@csimmons-astronomer

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

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions