Printing and PDF export are disabled for this content. View it online at Full Stack Learning Simplified.
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" # AtlasAtlas gives you a free managed cluster in minutes β the easiest way to start without installing anything.
Shell basics
| Command | Does |
|---|---|
show dbs | list databases |
use shop | switch to (and lazily create) a database |
show collections | list 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.
Free preview Β· Β© 2026 Full Stack Learning Simplified