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 myuserBasic Shell Commands
show dbs // list all databasesuse myapp // switch to (or create) a databaseshow collections // list collections in the current databasedb.users.find() // query the "users" collectionMongoDB 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 for | Scripting, automation, learning exact syntax | Visual exploration, quick data browsing |
| Learning curve | Requires knowing MongoDB's query syntax | More discoverable for beginners |
| Speed for repeated tasks | Faster once syntax is familiar | Faster 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.