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 27017Navigating 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
// ordersAll lessons in this course
- What Is a BSON Document?
- Collections vs SQL Tables
- Databases, Collections, and Namespaces
- The mongosh Shell Essentials