Installing MongoDB — MongoDB Technical Interview Questions & Answers

Setting up MongoDB locally on Windows/Mac/Linux.

Installing MongoDB

  • Simple meaning: You can run MongoDB on your laptop (Community Server) or in the cloud (Atlas). Students often find Atlas easier because there is nothing to install except mongosh or Compass.
  • Option A — Atlas (easiest): Go to mongodb.com/cloud/atlas → sign up → Build a free M0 cluster → Database Access (user + password) → Network Access (Add IP, or 0.0.0.0/0 only for practice) → Connect → copy the mongodb+srv:// string. Open Compass or mongosh with that URI.
  • Option B — Windows: Download MongoDB Community MSI from mongodb.com/try. Run installer. Tick “Install MongoDB as a Service” so it starts with Windows. Also tick Compass. After install, open Command Prompt and type mongosh. If “not recognized”, add C:\Program Files\MongoDB\Server\<version>\bin to PATH, or use “MongoDB Compass” from the Start menu.
  • Option C — Mac: brew tap mongodb/brew then brew install mongodb-community then brew services start mongodb-community. Then mongosh.
  • Option D — Linux (Ubuntu-style): follow the official MongoDB apt repo (do not use a random old package). Start the service, then mongosh.
  • Check it works: mongosh (local default is mongodb://127.0.0.1:27017). You should see a prompt. Type show dbs then help. First write creates a database: use college then the insertOne below.
  • First useful commands: use college db.students.insertOne({ name: "Asha", roll: 12, city: "Pune", marks: 72 }) db.students.find() show collections
  • Compass: GUI to click collections, run filters, and see documents. Same data as mongosh.
  • Common mistake: installing only Compass and wondering why mongosh is missing (install Shell / Database Tools too). Another: firewall blocking 27017. Atlas: forgetting to allow your IP, then “connection timed out”.
  • Interview tip: “Community on localhost:27017, or Atlas with mongodb+srv. mongosh to try queries. Compass to see documents.”

Technical Interview Tip: Install Community or Atlas, then mongosh + one insertOne. That is “installed”.

Code Examples for Installing MongoDB

Installing MongoDB — working example

// 1) Atlas: connect with your mongodb+srv URI
//    mongosh "mongodb+srv://USER:PASS@cluster0.xxxxx.mongodb.net/college"
// 2) Local Community: mongosh   (port 27017)
use college
db.students.insertOne({ name: "Asha", roll: 12, city: "Pune", marks: 72 })
db.students.find()
show dbs
show collections

Installing MongoDB — after Atlas or Community install, prove it: use college, insertOne, find. Compass uses the same URI.

How to Explain Installing MongoDB to an Interviewer

How do you install MongoDB as a student?

Atlas free cluster, or Community MSI / brew Prove it with mongosh and insertOne

Default local port?

27017