mongosh ("Mongo Shell") is MongoDB's official command-line tool for connecting to a database and running commands directly — everything in the CRUD lessons that follow can be typed straight into it.
Open a terminal and run mongosh followed by your connection string (from Atlas or a local install, per the previous lesson):
mongosh "mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/"A successful connection drops you into a prompt like test>, ready to run commands.
| Command | What it does |
|---|---|
| show dbs | Lists every database on this connection |
| use myDatabase | Switches to (or creates, on first write) a database |
| show collections | Lists every collection in the current database |
| db | Prints the name of the database you are currently using |
Switch to a fresh database and count the documents in a collection that does not exist yet — MongoDB does not error, it simply reports zero:
use learningMongo
db.users.countDocuments()
// 0Databases and collections appear on first write
MongoDB creates databases and collections lazily — nothing actually gets created on disk until you insert the first document into it. Running use someDatabase alone does not create anything yet.