Getting Your Connection String — MongoDB Technical Interview Questions & Answers
The mongodb+srv:// URI used by drivers.
Getting Your Connection String
- Simple meaning: The connection string is the address + login for your cluster.
- How to use: Atlas → Connect → Drivers → copy mongodb+srv://user:password@cluster.../college?retryWrites=true&w=majority
- Replace <password>. URL-encode special characters (@ becomes %40).
- Local looks like mongodb://127.0.0.1:27017/college
- Common mistake: leaving <password> in the string. Committing it to GitHub.
- Interview tip: mongodb:// vs mongodb+srv://. Password encoding. Database name in the path.
Technical Interview Tip: Show both URI shapes and where the DB name goes.
Code Examples for Getting Your Connection String
Getting Your Connection String — working example
// URI forms used by mongosh and drivers:
// mongodb://user:pass@localhost:27017/prep_pilot?authSource=admin
// mongodb+srv://user:pass@cluster0.example.mongodb.net/prep_pilot?retryWrites=true&w=majority
mongosh "mongodb://localhost:27017/prep_pilot"
db.users.findOne()Getting Your Connection String — mongodb:// is standard; mongodb+srv:// is Atlas DNS seed-list style.
How to Explain Getting Your Connection String to an Interviewer
What is mongodb+srv?
Atlas DNS seed-list URI Used instead of listing every host