Chapter 20. Starting and Stopping MongoDB
In Chapter 2, we covered the basics of starting MongoDB. This chapter will go into more detail about which options are important for setting up MongoDB in production, including:
Commonly used options
Starting up and shutting down MongoDB
Security-related options
Logging considerations
Starting from the Command Line
The MongoDB server is started with the mongod executable. mongod has many configurable startup options; to
view all of them, run mongod --help
from the command line. A couple of the options are widely used and
important to be aware of:
--dbpathSpecify an alternate directory to use as the data directory; the default is /data/db/ (or, on Windows, \data\db\ on the MongoDB binary’s volume). Each
mongodprocess on a machine needs its own data directory, so if you are running three instances ofmongodon one machine, you’ll need three separate data directories. Whenmongodstarts up, it creates a mongod.lock file in its data directory, which prevents any othermongodprocess from using that directory. If you attempt to start another MongoDB server using the same data directory, it will give an error:"Unable to acquire lock for lockfilepath: /data/db/mongod.lock."--portSpecify the port number for the server to listen on. By default,
mongoduses port 27017, which is unlikely to be used by another process (besides othermongodprocesses). If you would like to run more than onemongodprocess on a single machine, you’ll need to specify different ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access