0Pricing
MongoDB Academy · Lesson

The mongosh Shell Essentials

Learners will use mongosh to switch databases, list collections, and run their first document queries interactively.

What Is mongosh?

mongosh is MongoDB's official shell, built on Node.js — so you can use modern JavaScript right inside it. It's the standard way to connect from the command line.

# Install mongosh on macOS
brew install mongosh

# Connect to a local MongoDB instance
mongosh

# Connect to an Atlas cluster
mongosh 'mongodb+srv://user:pass@cluster0.abc.mongodb.net/myapp'

# Connect with explicit host and port
mongosh --host localhost --port 27017

Navigating Databases and Collections

A few commands help you get around: show dbs lists databases, use switches one, and show collections lists what's inside. The db variable is always your current database.

// Navigate in mongosh
show dbs
// admin   0.000GB
// myapp   0.008GB

use myapp
// switched to db myapp

db
// myapp

show collections
// users
// orders

All lessons in this course

  1. What Is a BSON Document?
  2. Collections vs SQL Tables
  3. Databases, Collections, and Namespaces
  4. The mongosh Shell Essentials
← Back to MongoDB Academy