Loading

Quipoin Menu

Learn • Practice • Grow

mongodb / MongoDB Compass & Shell
tutorial

MongoDB Compass & Shell

Now that MongoDB is installed, you need tools to interact with it. MongoDB provides two main ways: **MongoDB Compass** (a graphical user interface) and **MongoDB Shell** (a command-line tool). Let's explore both.

What is MongoDB Compass?

MongoDB Compass is a GUI tool that lets you visualize and interact with your data without typing commands. It's great for beginners and for exploring databases visually.

Think of Compass as Google Maps for your database – you can see everything visually. The Shell is like using GPS commands – more powerful but needs typing.

Installing MongoDB Compass
  1. Go to MongoDB Compass Download
  2. Download the version for your operating system.
  3. Install like any other application.
  4. Open Compass and you'll see a connection screen.

Connecting with Compass

For Local MongoDB: Just click "Connect" – default is `localhost:27017`
For Atlas: Paste your connection string and click "Connect"

Once connected, you'll see your databases and collections. You can:
  • Create/drop databases
  • Create/drop collections
  • Insert/edit/delete documents visually
  • Run queries with a visual query builder
  • View data in table or JSON format

What is MongoDB Shell (mongosh)?

MongoDB Shell is a command-line interface for MongoDB. It's more powerful and faster once you learn the commands.

Installing MongoDB Shell

If you installed MongoDB locally, the shell usually comes with it. To check:
mongosh --version

If not installed, download from MongoDB Shell Download

Basic Shell Commands

CommandDescription
`mongosh`Start the shell (connect to local MongoDB)
`show dbs`List all databases
`use mydb`Switch to/create database 'mydb'
`show collections`List all collections in current database
`db.stats()`Show database statistics
`exit`Exit the shell

Example: First Shell Session
$ mongosh
test> show dbs
admin 100 kB
config 100 kB
local 100 kB

test> use myblog
switched to db myblog

myblog> db.posts.insertOne({ title: "Hello", content: "First post!" })
{
  acknowledged: true,
  insertedId: ObjectId("65a1b2c3d4e5f6a7b8c9d0e1")
}

myblog> show collections
posts

myblog> db.posts.find()
[
  { _id: ObjectId("65a1b2c3d4e5f6a7b8c9d0e1"), title: "Hello", content: "First post!" }
]

Two Minute Drill

  • MongoDB Compass is a GUI tool – great for beginners and visual exploration.
  • MongoDB Shell (mongosh) is a command-line tool – faster and more powerful.
  • Both can connect to local MongoDB or Atlas.
  • Basic shell commands: `show dbs`, `use dbname`, `show collections`.
  • Start with Compass, then learn shell for more control.

Need more clarification?

Drop us an email at career@quipoinfotech.com