Can't connect to MongoDB from Glitch

@RobotFights Atlas is pretty cool, by default it sets up a DNS which connects through to one of several servers for load balancing. That makes the connection string more complicated, but Atlas constructs it for you, see screenshots below.

Mine looks like:

mongodb+srv://MONGODB_USER:MONGODB_PASS@MONGODB_HOST/MONGODB_DB?retryWrites=true&w=majority

If the username or password has special characters that are understood by URLs, such as colon or dollar sign, you can encode them before joining them together in a string:

"mongodb+srv://" + encodeURIComponent(process.env.MONGODB_USER) + ":" + encodeURIComponent(process.env.MONGODB_PASS) + "@" + process.env.MONGODB_HOST + "/" + process.env.MONGODB_DBNAME + "?retryWrites=true&w=majority"
Screenshots

2019-08-28%2022_28_54-Clusters%20_%20Atlas_%20MongoDB%20Atlas

2019-08-28%2022_29_25-Clusters%20_%20Atlas_%20MongoDB%20Atlas

2019-08-28%2022_30_18-Clusters%20_%20Atlas_%20MongoDB%20Atlas

1 Like