Connecting with mongosh — MongoDB Technical Interview Questions & Answers
Connecting to local and remote MongoDB instances.
Connecting with mongosh
- Simple meaning: mongosh with a URI tells the shell which server, user, and database to use.
- How to use: mongosh "mongodb://127.0.0.1:27017" Atlas: mongosh "mongodb+srv://user:pass@cluster0.xxxxx.mongodb.net/college".
- Inside the shell: db.getMongo() shows the connection.
- Common mistake: special characters in the password not URL-encoded. Atlas IP not allowed.
- Interview tip: mongodb:// local, mongodb+srv Atlas. Port 27017 local default.
Technical Interview Tip: Show one local URI and one Atlas SRV.
Code Examples for Connecting with mongosh
Connecting with mongosh — working example
mongosh "mongodb://localhost:27017/prep_pilot"
const ada = db.users.findOne({ email: "ada@example.com" })
ada.skills
db.users.find({ city: ada.city })Connecting with mongosh — mongosh is the modern MongoDB shell; you can store query results in variables.
How to Explain Connecting with mongosh to an Interviewer
Default local URI?
mongodb://127.0.0.1:27017