LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 714 min read

MongoDB Shell & Compass

Connect to your cluster and explore data using mongosh, the MongoDB Shell, and MongoDB Compass's visual interface.

mongosh: The MongoDB Shell

mongosh is MongoDB's official command-line shell, built on JavaScript — every command you type is JavaScript, and query results are plain JavaScript objects.

mongosh "mongodb+srv://cluster0.abcde.mongodb.net/" --username myuser

Basic Shell Commands

show dbs // list all databases
use myapp // switch to (or create) a database
show collections // list collections in the current database
db.users.find() // query the "users" collection
Databases and Collections Are Created Lazily

MongoDB doesn't require you to explicitly create a database or collection ahead of time — using them, or inserting the first document into them, is what actually creates them.

MongoDB Compass

Compass is MongoDB's official GUI — it lets you browse databases and collections, build queries visually, view an aggregation pipeline's output stage by stage, and inspect indexes, all without typing shell commands.

Visual Query Builder

Build filters and see results update live, without writing raw shell syntax.

Schema Analysis

Compass samples your documents and shows the shape and types of your data.

Performance Insights

Visualize explain() output and index usage for a query.

Choosing Shell vs Compass

mongosh (Shell)Compass (GUI)
Best forScripting, automation, learning exact syntaxVisual exploration, quick data browsing
Learning curveRequires knowing MongoDB's query syntaxMore discoverable for beginners
Speed for repeated tasksFaster once syntax is familiarFaster for one-off visual exploration

FAQs

Yes — this course teaches shell syntax throughout, since it's also exactly what you'll write in application code and scripts; Compass is a great complement for visual exploration.

Yes — since mongosh is a full JavaScript environment, you can use variables, loops, and functions alongside your database commands.

Summary

mongosh and Compass are two complementary ways to interact with the exact same underlying data. With setup complete, the next section dives into MongoDB's core concepts, starting with documents and collections themselves.

Next Lesson →

Documents & Collections