The mongod.cfg file for configuring the mongod process
So with mongodb there is the mongod binary that is the actually process daemon or service that handles requests for data in a database. It other words it is what always runs in the background on the computer that is hosting the database that is being used in a project that makes use of mongodb. Well one thing that might come of interest with this is how to configure mongodb with settings like the port to listen on, and if authentication should be enabled or not. Well one way is to give some of these options to the binary via the command line when staring it, but maybe a better way is to park these settings in a configuration file of sorts, thats where the mongod.cfg file comes into play. In this post I will be giving a quick overview of
1 - what to know
This is a post on the config file that is used to configure the mongod process. In this post I am using mongodb 4.0, and the config file that I am writing about is in the yaml format. In older versions of mongodb this file may be of a different format.
2 An example of mongod.cfg
An example of a mongod.cfg file that I have in a windows environment looks like this.
Regardless of the operation system environment, you want the paths to be absolute paths. In fact I would say that using absolute paths in general is good practice, but that is getting off topic. In a posix environment that might be the only note worthy difference though. In a Linux environment where I have another setup the config file is in a different format, because it is an older version of mongodb, so I will not be writing about there here.
2.1 - Storage Options
For storage options this is where I set the path where the database folder will be by giving an absolute path to the desired location.
Here journaling should be enabled, it often is be default. This helps when it comes to unclean shutdowns.
2.2 - System log options
here I set the location of the system logs where I should look when something goes wrong to see what the problem might be.
2.3 - Network interfaces
Here I set the port, and the ip to bind to. In most cases so far I am just working with mongodb locally, when I go to deploy I dot have to wory about much of this, ans the default settings work okay.
2.4 - Security settings
So far I have only been playing with authentication, when I go to deploy an app authentication is enabled so I only enabled this and set up user accounts to help better emulate what I am dealing with when I go to deploy. For the most part this is the only reason why I bother with this at all when working with mongodb locally.
3 - Conclusion
Thats it for now, I might write more about this if I play around with mognodb more however do not hold your breath. Most of my future content on mongodb will likely be on mongo clients like mongoose, when it comes to working with mngodb with respect to making apps, rather than fiddling with config files.