Before writing your first query, there are foundations to put in place: basic terminal CLI skills and an understanding of the JSON data format, installing MongoDB Community Server via Docker or natively, and verifying that mongosh successfully connects to the database server.

Welcome to the Learning MongoDB series! This series will take you from zero to being ready to build and operate MongoDB at production scale: starting from pre-requisites and environment setup, the history of NoSQL, core data structure concepts, CRUD, advanced queries, schema design, aggregation, indexing, transactions, replica sets, sharding, security, all the way to a production-grade e-commerce architecture case study. A total of 21 episodes that will change the way you think about data storage.
Why is MongoDB so important? Because the modern era is full of semi-structured data that doesn't always fit into rigid tables. MongoDB comes in as a document database with a flexible schema, the BSON data format, and native horizontal scaling capabilities. A backend developer who understands MongoDB will be far better equipped to handle modern workloads: product catalogs with dynamic attributes, event streaming, real-time analytics, and large-scale applications.
Episode 0 is your roadmap. Before discussing documents and queries, we make sure of three things: (1) the basic terminal and JSON skills you must master, (2) a correct MongoDB Community Server installation, and (3) verification that the mongosh client successfully talks to the server. Don't skip around — a shaky foundation will make the following episodes feel heavy. Let's get started.
MongoDB is a product that lives in the terminal. You'll type mongosh commands, run backup scripts, and read server logs every day. Make sure you're comfortable with the following:
pwd, cd, ls to move around and inspect directories.systemctl start mongod or docker start mongo to bring the database server up.ps aux | grep mongod to make sure the server is running.27017 at localhost by default.pwd
ls -la
systemctl status mongod
ss -tlnp | grep 27017ss -tlnp | grep 27017 shows whether there is any process listening on port 27017 — your first debugging tool when the server can't be reached.
MongoDB stores data in the BSON format, which is very close to JSON. Before learning MongoDB, you must be comfortable reading and writing JSON: objects { "key": "value" }, arrays [1, 2, 3], and even nested documents. Here is an example of a simple JSON document that will look very much like a MongoDB document:
{
"name": "Arman",
"role": "backend-engineer",
"skills": ["nodejs", "mongodb", "docker"],
"address": {
"city": "Jakarta",
"country": "Indonesia"
},
"isActive": true,
"age": 27
}Notice that fields can hold different data types: string, boolean, number, array, and even nested objects. This is the power of a document database — you don't need to define columns in advance.
The fastest and cleanest approach is using Docker. The official mongo image is available for MongoDB Community Server, and you can run it with a single command:
docker run --name mongo -p 27017:27017 -d mongo:7The -p 27017:27017 option maps the container port to the host port, so clients on the host can access the database via mongodb://localhost:27017. The container name mongo makes it easy to stop and restart later.
docker ps
docker logs mongo
docker stop mongo
docker start mongodocker logs mongo is your main window into the server's startup messages, including the Waiting for connections line that signals MongoDB is ready to accept connections.
If you're not using Docker, MongoDB can be installed directly on your operating system. On Ubuntu/Debian you can use the official packages from the MongoDB repository:
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt update
sudo apt install -y mongodb-org
sudo systemctl enable --now mongodOn macOS, brew tap mongodb/brew && brew install mongodb-community is the easiest way. On Windows, use the official MSI installer from the MongoDB website and run MongoDB as a service.
mongosh is the modern MongoDB Shell built on Node.js — the replacement for the legacy mongo shell that has long been deprecated. It's your primary tool throughout this series for writing queries interactively. Once the server is running, connect to the local server:
mongosh "mongodb://localhost:27017"You can also connect directly to a specific database:
mongosh "mongodb://localhost:27017/belajar"Once you're in, verify the connection with a simple command:
Current Mongosh Log ID: 66xxxxxxxxxxxxxxxxxxxxxxxx
Connecting to: mongodb://localhost:27017/belajar
test> show dbs
admin 40.00 KiB
config 12.00 KiB
local 72.00 KiBshow dbs lists the available databases. The three default databases (admin, config, local) are always present; the belajar database doesn't show up yet because there's no data in it — MongoDB creates databases lazily the first time data is written.
The terminal is powerful, but sometimes you need a visual view of your data. There are several popular GUI options:
For this series, my recommendation is MongoDB Compass because it's free and official. Download it from the official MongoDB website, match its version to your server version, then connect to mongodb://localhost:27017.
Now let's string together everything we've set up into a series of tests that ensure your environment is truly ready. Run each one and make sure the output matches:
mongosh --version
docker ps
mongosh "mongodb://localhost:27017" --eval "db.runCommand({ ping: 1 })"{
"ok": 1
}mongosh --version confirms the client is installed and returns a version (e.g. 2.x).docker ps confirms the mongo container is in the Up status.ping command with --eval confirms the client and server can talk to each other — the { "ok": 1 } response means the connection is perfect.Info
Get into the habit of keeping small notes about the versions you use (MongoDB server, mongosh, and OS). Versions greatly affect features: for example, $setWindowFields only became available in MongoDB 5.0+, while certain aggregate stages only appear in newer versions. This series uses MongoDB 7.x as its baseline.
The server isn't running. You get an ECONNREFUSED error when entering mongosh. Solution: check docker ps for Docker, or systemctl status mongod for a native install.
The port is already in use. If another application is occupying port 27017, MongoDB fails to start. Check with ss -tlnp | grep 27017, kill the process that owns the port, or run MongoDB on a different port.
Using the legacy mongo shell. The mongo shell is deprecated and isn't compatible with MongoDB 6+. Make sure what's installed is mongosh, not mongo.
Skipping verification. Skipping the ping test means you don't know whether your environment is actually healthy. Always verify after any installation.
Docker container not persistent. Running docker run --rm deletes data as soon as the container stops. For data you want to keep, use a volume (-v mongo-data:/data/db) — we'll cover this in depth in the backup episode.
Warning
For a learning setup, a default installation without a username and password is perfectly normal — a local connection with no authentication. But as soon as MongoDB is used beyond your laptop (a cloud server, Docker exposed to the network), authentication and TLS must be enabled. We'll cover security thoroughly in episode 17. For now, just understand that MongoDB's defaults are not safe for public networks.
In episode 0 you secured three foundations: basic terminal CLI skills (filesystem navigation, process management, understanding port 27017) and an understanding of the JSON format as MongoDB's primary language, a MongoDB Community Server installation via Docker or natively, and connection verification through mongosh and the ping command that returns { "ok": 1 }.
Key takeaways:
27017; make sure the server is alive before connecting.mongosh is the modern shell that replaces the legacy mongo — get used to using it.db.runCommand({ ping: 1 }) after any setup.Remember, the Learning MongoDB series consists of 21 episodes that build on each other. Episode 0 is the first brick — and you've just laid it. In the next episode, episode 1, we take a step back to understand the history, the NoSQL concept, and why choose MongoDB: the limitations of classic RDBMS, the four NoSQL categories, the birth of MongoDB from 10gen's hands, and its comparison with PostgreSQL, DynamoDB, and Firestore. See you in episode 1, and happy building your MongoDB laboratory!