Now that we talked about the different options you can set and you can use to run your mongodb
server,
it's also worth mentioning that you can save your settings in a configuration file.
If you google for mongodb config file,
you should find this article from the official docs and there, you can learn that you can create a
mongodb config file and you might also get one by default
after your installation but I for example did not get one on Mac. So you might get one
otherwise you can simply create one and you can create it anywhere you want and I will do that too.
I will create a config file here in my bin folder let's say, I actually did already create one
I name it mongodb.cfg,
so you can simply create this with a text editor. And here I'll edit it with Visual Studio code because that
is a nice editor for this and makes well reading that file really easy.
Now you see I already have a file where I added some settings and this is how you do add settings and
you find detailed instructions in an article I just pointed you at,
there you also find one example of config file
and if you google for mongodb example of config file, you also find more examples by other users.
Now this is a more comprehensive file,
I've got a very simple file here,
in the end I here only set the path to my database, so where all the database files should be stored
and to my log files
and I also explicitly need to tell mongodb that this path points at a log file and that is my
mongodb config file.
Now the question just is
how do I use that file when starting a new mongodb instance?
And it's not the case that mongod would pick up this file automatically because how would it know that
it should, that this file exists and where it could find this file. Instead
when starting mongodb, you can use the --config option or a shortcut for that, -f and then
pass a path to the config file,
so in my case that's in my mongodb folder /bin/mongod.cfg and you could also name this conf,
that doesn't really matter.
With that, you could hit enter and it should now still start
your mongodb server with the setting set up in the configuration file
and this is of course a very useful feature too because this allows you to basically save a snapshot
of your settings,
a reuseable blueprint all of your settings in a separate file which you can then always well use for
starting up your server and you can find all the information about all the possible options and what
they do
in this article I pointed you at.
So if you want to dive deeper into this, definitely check out this article. With that and with the settings
you saw in the other lectures,
you should have a solid toolset of working with the
mongodb server and starting it in the way you want it to start.