Install MongoDB and Connect

Run MongoDB locally, in Docker, or use the free MongoDB Atlas cloud. Connect with mongosh, the modern interactive shell.

Getting a database

bash
# Docker (no local install)
docker run -d -p 27017:27017 mongo:8

# then connect
mongosh                                    # local, default port 27017
mongosh "mongodb+srv://user:pass@cluster.mongodb.net"   # Atlas

Atlas gives you a free managed cluster in minutes β€” the easiest way to start without installing anything.

Shell basics

CommandDoes
show dbslist databases
use shopswitch to (and lazily create) a database
show collectionslist collections in the current db
db.products.find()query a collection

The connection string

Apps and tools connect with a URI: mongodb://host:27017/dbname (or mongodb+srv://... for Atlas). It carries the host, credentials, database, and options.

Databases are lazy

Note: use shop doesn't create the database immediately β€” MongoDB creates the database and collection on the first insert. So you can use a name that doesn't exist yet.
Tip: MongoDB Compass is the official free GUI for browsing documents, building queries visually, and viewing indexes β€” great alongside mongosh while you learn.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
Install MongoDB and Connect β€” MongoDB | Full Stack Learning Simplified