Skip to content

Issue with APOS_MONGODB_URI Setting for Replica Set Connection #4659

@rredaelli

Description

@rredaelli

Hi,
I am experiencing an issue when setting the APOS_MONGODB_URI environment variable with a connection string for a MongoDB replica set. Despite following the correct format, the connection does not work and throws an error.

Here is the value I am using for APOS_MONGODB_URI:
APOS_MONGODB_URI=mongodb://XXXXXXXXXX:[email protected]:27017,XXX.XXX.XX.X:27017,XXX.XXX.XX.X:27017/DB_NAME?w=majority&retryWrites=true&replicaSet=rs_p20_coll&authSource=admin

Below is the error message that I am encountering:

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:637:13)
    at module.exports (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/lib/mongodb-connect.js:19:18)
    at Object.connectToMongo (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/modules/@apostrophecms/db/index.js:120:36)
    at Object.init (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/modules/@apostrophecms/db/index.js:60:16)
    at self.create (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/lib/moog.js:294:20)
    at async instantiateModules (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/index.js:590:22)
    at async apostrophe (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/index.js:298:5)
    at async /opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/index.js:157:17
    at async module.exports (/opt/stagecoach/apps/p20_cultura/deployments/2024-07-25-17-17-47/node_modules/apostrophe/index.js:156:16) {
  input: 'mongodb://XXXXXXXXXX:[email protected]:27017,XXX.XXX.XX.X:27017,XXX.XXX.XX.X:27017/DB_NAME?w=majority&retryWrites=true&replicaSet=rs_p20_coll&authSource=admin',
  code: 'ERR_INVALID_URL'
}

It seems that the URL is not being parsed correctly, resulting in the ERR_INVALID_URL error. I've verified that the credentials, IP addresses, and other parameters are correct.

Could you please assist in identifying the issue or provide guidance on the correct configuration for connecting to a MongoDB replica set using APOS_MONGODB_URI?
For info: I am on Apostrophe v3.67.0.

Thank you for your help!

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