O'Reilly logo

MongoDB: The Definitive Guide, 3rd Edition by Kristina Chodorow, Shannon Bradshaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 21. Setting Up MongoDB in Production

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:

--dbpath

Specify 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 mongod process on a machine needs its own data directory, so if you are running three instances of mongod on one machine, you’ll need three separate data directories. When mongod starts up, it creates a mongod.lock file in its data directory, which prevents any other mongod process from using that directory. If you attempt to start another MongoDB server using the same data directory, it will give an error:

exception in initAndListen: DBPathInUse: Unable to lock the
          lock file: \ data/db/mongod.lock (Resource temporarily unavailable).
          Another mongod instance is already running on the 
          data/db directory,
          \ terminating
--port

Specify the port number for the server to listen on. By default, mongod uses port 27017, which is unlikely to be used by another ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required