What the mongod server process does, how it differs from mongos and mongosh, the options and config file that control it, and how to start and stop it safely.
mongod is the MongoDB server. It is the process that owns the data files, listens on a TCP port (27017 by default), executes reads and writes, maintains indexes and replicates data to other members of a replica set. The name is short for "mongo daemon". If MongoDB is "running" on a machine, a mongod process is running there.
Start one in the foreground with a data directory of your choice:
The log is written to the terminal as one JSON object per line. The server is ready when a line with "msg":"Waiting for connections" appears. Press Ctrl+C to shut it down cleanly.
mongod, mongos and mongosh
Three programs with similar names do different jobs:
Program
What it is
When you run it
mongod
The database server. Stores data and answers queries.
Always. Every deployment is one or more mongod processes.
mongos
A router for sharded clusters. Stores no data; forwards each operation to the shards that hold the relevant data and merges the results.
Only in a sharded cluster. Applications connect to mongos instead of to a mongod.
mongosh
The interactive shell: a client, like psql or the mysql command.
Whenever you want to type queries or administrative commands.
mongosh replaced the older mongo shell, which was deprecated in MongoDB 5.0 and removed from the server packages in 6.0. If a tutorial tells you to run mongo and the command is not found, run mongosh. It is a separate download from the server on some platforms.
With no arguments mongosh connects to mongodb://localhost:27017:
A server selection timeout means the driver can't reach the cluster; a pool timeout means you've run out of connections. How to diagnose each, including the serverless one-client-per-request trap.
Starting mongod by hand is fine for experiments. On a real server it runs as a service that reads a configuration file.
Platform
Start, stop, status
Configuration file
Linux (official packages)
sudo systemctl start mongod, stop, status
/etc/mongod.conf
Windows (MSI installer)
The MongoDB service: net start MongoDB, net stop MongoDB
<install directory>\bin\mongod.cfg
macOS (Homebrew)
brew services start mongodb-community (or the versioned formula you installed)
mongod.conf under the Homebrew prefix
On Linux, enable the service at boot with sudo systemctl enable mongod.
A hand-started mongod and the packaged service do not use the same defaults. With no options, mongod stores data in /data/db (\data\db on the current drive on Windows) and exits if that directory does not exist. The packages ship a configuration file that points somewhere else, such as /var/lib/mongodb on Debian and Ubuntu. Running a bare mongod on a machine where the service is installed therefore starts a second, empty server, or fails because the port is taken; it does not start "your" database.
Run a server with it using mongod --config /etc/mongod.conf (or -f). YAML is indentation-sensitive and does not allow tab characters; a tab in this file stops the server from starting.
Core options
Every setting can be given on the command line or in the file. The ones you will meet first:
Command-line option
Config file setting
What it does
--dbpath <dir>
storage.dbPath
Directory for data files. Must exist and be writable by the user running mongod.
--port <n>
net.port
TCP port to listen on. Default 27017.
--bind_ip <addresses>
net.bindIp
Network interfaces to listen on. Default is localhost only.
--logpath <file>
systemLog.path
Write the log to a file instead of standard output. Add --logappend to keep the existing file on restart.
--auth
security.authorization: enabled
Require clients to authenticate and enforce role-based access control.
--replSet <name>
replication.replSetName
Run as a member of the named replica set.
--maxConns <n>
net.maxIncomingConnections
Upper limit on simultaneous client connections.
--fork
processManagement.fork
Detach and run in the background. Needs --logpath. Not available on Windows; not needed under systemd.
--config <file>
Read settings from a configuration file.
--version, --help
Print the version or the option list and exit.
Two of these deserve attention.
bindIp. A new mongod accepts connections only from the same machine. That is deliberate: early MongoDB versions listened on every interface by default, and many unsecured databases ended up reachable from the internet. To accept remote clients, add the server's private address (bindIp: 127.0.0.1,10.0.1.15). A replica set also needs this, because the members must reach each other.
authorization. Access control is off unless you turn it on. Without it, anyone who can reach the port has full access. Before you change bindIp, create an administrative user and enable authorization:
Then set security.authorization: enabled, restart mongod, and connect with mongosh -u admin -p --authenticationDatabase admin.
To see which options a running server was started with, ask it:
db.serverCmdLineOpts()
db.version()
Storage and memory
mongod uses the WiredTiger storage engine. The older MMAPv1 engine was removed in MongoDB 4.2. Journaling is always on in current versions, which is what makes recovery after a crash possible.
By default WiredTiger's internal cache takes the larger of 50% of (RAM minus 1 GB) or 256 MB, and the operating system's file cache uses more on top. This default assumes one mongod per machine. If you run several on one host or run it in a container alongside other software, set storage.wiredTiger.engineConfig.cacheSizeGB explicitly.
Shutting down mongod
A clean shutdown finishes pending operations, flushes data to disk and closes the files. Use one of these:
From the service manager (the normal way):
sudo systemctl stop mongod # Linux
net stop MongoDB # Windows, in an Administrator prompt
From mongosh, on any platform:
use admin
db.shutdownServer()
db.adminCommand({ shutdown: 1 }) is the equivalent command. With authorization enabled, your user needs a role that permits shutdown, such as hostManager or clusterAdmin; the user-administration roles alone are not enough.
With Ctrl+C, if mongod is running in the foreground of a terminal.
With a signal, on Linux and macOS. SIGTERM (the default for kill) and SIGINT both trigger a clean shutdown:
kill <mongod process id>
With --shutdown, on Linux only. It needs the same data directory setting the server was started with:
mongod --shutdown --dbpath /var/lib/mongodb
Never use kill -9. SIGKILL gives the process no chance to shut down cleanly. The journal normally lets mongod recover on the next start, but recovery takes time and you are relying on it for no reason.
When the server is the primary of a replica set, a shutdown first steps it down so another member can take over. If no secondary is close to up to date, db.shutdownServer() refuses to proceed; pass { timeoutSecs: 60 } to wait for one to catch up, or { force: true } to shut down anyway.
Troubleshooting start-up
Read the log first: the terminal for a foreground process, otherwise the file named by systemLog.path. The usual causes are:
Symptom
Cause and fix
Exits at once with Data directory /data/db not found
No --dbpath or config file was given and the default directory does not exist. Create it, or point to the directory you intended.
Address already in use for port 27017
Another mongod is already running, often the system service. Stop it or use another --port.
Permission denied on the data or log directory
The directory is owned by a different user, commonly after running mongod once as root. Fix the ownership to the service account (mongodb on Debian and Ubuntu, mongod on RHEL-family systems).
Service fails right after you edit the config file
A YAML error: a tab, wrong indentation or a misspelt key.
Process dies with Illegal instruction
MongoDB 5.0 and later need a CPU with AVX on x86-64. This shows up on old hardware and on some virtual machines that mask CPU features.
Twelve common MongoDB relationships, from user addresses to org charts, each with an embed, reference or hybrid verdict, the document shape and the reason.
A complete schema for a multi-tenant project tracker: collections, types, ESR indexes checked with explain(), validation, migrations, write concerns and sharding readiness.