Skip to content

MongoDB Fundamentals

MongoDB Compass and Shell

Two ways to talk to a cluster: a GUI for exploring, a shell for the queries you will write in interviews.

BeginnerAbout 3 minutes

Two tools, same database. Compass is the GUI: browse collections, click a document, run a query, look at an explain plan later. mongosh is the shell: the same queries you will type in an interview and paste into a backend.

Compass

  • See collections and documents
  • Build a filter without memorising syntax
  • Inspect a single document's shape
  • Useful when you do not know the data yet

mongosh (the shell)

  • Run queries as code
  • What interviewers expect you to write
  • Same `db.users.find(...)` as the docs
  • Light admin: `show dbs`, `use`, indexes later
show dbs
use app
show collections
db.users.find({ city: "Bangalore" })
A few commands. This is not a shell course.
{ _id: ObjectId("64a1b2c3d4e5f6a7b8c90001"), name: "Rahul", city: "Bangalore", ... }
find() in the shell prints matching documents

use app sets the current database. Then db is app, and db.users is the collection. Compass does the same thing with a dropdown. The next two lessons are how Node.js speaks this protocol without a GUI.

Interview question

When would you use Compass versus the MongoDB shell?

Think about it first.