新手求助:goorm IDE连接MongoDB Atlas时出现认证失败错误
Hey Dylan, sorry to hear you're stuck with this auth error! Let's walk through the most common fixes for this bad auth Authentication failed issue, since you already sorted the IP whitelist (0.0.0.0/0 is correct for allowing all connections).
1. Fix the Connection String's Escaped Ampersand
Looking at your code, the biggest red flag is the & in your MongoDB connection string. This is an HTML-escaped version of &, and Mongoose will interpret it as part of the string rather than a parameter separator—this is almost certainly causing part of your auth issue.
Your current connection string:
mongoose.connect('mongodb+srv://dylanOh:123456@cluster0-1kwgi.mongodb.net/test?retryWrites=true&w=majority',{ useNewUrlParser : true, useCreateIndex : true })
Replace it with this (swap & for & + add a critical connection parameter):
mongoose.connect('mongodb+srv://dylanOh:123456@cluster0-1kwgi.mongodb.net/test?retryWrites=true&w=majority',{ useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
I added useUnifiedTopology: true—this is required for newer Mongoose versions to properly handle Atlas's cluster topology, which can also cause silent connection failures.
2. Double-Check Your Atlas Database User Credentials
Even tiny typos can break authentication:
- Head to your MongoDB Atlas dashboard → Database Access
- Verify the username is exactly
dylanOh(usernames are case-sensitive!) - Confirm the password matches
123456—if you recently updated it, make sure the string in your code reflects the new password. (Note: If your password had special characters, you'd need to URL-encode them, but123456is safe as-is.)
3. Ensure Your Atlas User Has Proper Permissions
Make sure the database user you created has enough access to connect and interact with the database:
- In Database Access, edit the
dylanOhuser - Under "Built-in Role", select at least
readWrite(ordbOwnerfor full access during testing) - Save the changes and wait 1-2 minutes for permissions to propagate across Atlas's servers
4. Verify Mongoose Version Compatibility
Outdated Mongoose versions can have bugs with Atlas's SRV connection strings. Run this in your Goorm IDE terminal to check your version:
npm list mongoose
If it's older than v5.10.0, update it with:
npm install mongoose@latest
Try these steps in order—fixing the & issue is the most likely quick win here. Once you make the changes, restart your server and see if you get the "Connected to DB!" message.
内容的提问来源于stack exchange,提问作者Dylan Oh

