What is the MongoDB Shell (mongosh)? — MongoDB Technical Interview Questions & Answers
An interactive JavaScript-based CLI for MongoDB.
What is the MongoDB Shell (mongosh)?
- Simple meaning: mongosh is the official MongoDB shell — a terminal where you type JavaScript-like commands against the database.
- How to use: after install, type mongosh. Local: mongosh. Atlas: mongosh "mongodb+srv://..." . Old name was mongo (legacy).
- Try this: help then show dbs then use college.
- You can use variables: const s = db.students.findOne({ roll: 12 }).
- Common mistake: thinking Compass and mongosh are different databases. Same server, two clients.
- Interview tip: mongosh = CLI client. Compass = GUI. Both use the same URI.
Technical Interview Tip: mongosh connects; Compass is the GUI for the same DB.
Code Examples for What is the MongoDB Shell (mongosh)?
What is the MongoDB Shell (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 })What is the MongoDB Shell (mongosh)? — mongosh is the modern MongoDB shell; you can store query results in variables.
How to Explain What is the MongoDB Shell (mongosh)? to an Interviewer
What is mongosh?
The MongoDB shell Interactive CLI to run find/insert