feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 744 forks source link

fix(generators): Harden mongodb.js to reliably extract database from any connection string #3264

Closed jermsam closed 6 months ago

jermsam commented 10 months ago

The default connection for mongodb in mongodb.js fails when you try to connect with a connection string that uses mongodb-replicas sets or clusters ... (eg: mongodb://localhost:27017,127.0.0.1:27018/mo-db?replicaSet=rs0) ... This is because new URL(connection).pathname.substring(1) fails with an is not a valid URL error .... I propose the following replacement to mongodb.js as it will satisfy all most all formats of connection strings

daffl commented 9 months ago

Thank you for putting this PR up (and sorry for the late reply). I wonder if we should make this a helper since we'd want the generated code to be as short as possible.

jermsam commented 8 months ago

Let me optimize it to be as short as possible

jermsam commented 8 months ago

it's now just one additional line of code from what it was originally

daffl commented 6 months ago

Thank you for updating and sorry for the delay.

daffl commented 6 months ago

Apologies again but I had to revert the merge. I thought the tests were failing because things weren't up to date with latest but the error was actually an invalid regular expression that I wasn't able to fix (see errors in https://github.com/feathersjs/feathers/actions/runs/7427523402/job/20213354620#step:8:3307). You can run all test locally by running npm test in the main repo.