So there's a bunch of stuff we can configure and what exactly can we configure there or what could
be interesting to us?
Well things like quiet allow you to change the way things get logged or output by the server
and if you feel like it's talking too much to you, you can control that with quiet
and obviously check out the official docs for more detailed explanations of all the options. Interesting
to us is the log path and also another setting, the db path which you can find a bit further down towards
the end of this list.
These two path allow you to configure where your data gets stored in the case of db path because
mongodb of course does write your data to real files on your system,
so the db path is where these files will live and the log path is essentially where the logs will
be written to and the logs are interesting because in the logs, you can then see for example warnings
of json schema validation, warnings
if you set the validation action to warning, what we did in a previous module. So log path and db
path can be set,
now how do we set this?
I'm in my mongodb folder and there, I got that bin folder
Now in this mongodb folder, I'll create a new path and I'll name it db and I'll create another
new folder and I'll name it
logs, you can name these folders however you want.
Now these are two new folders and I want to use the db folder for my db files and the logs folder
for my logs, the default setting for db is that it will use my root folder and there, the data db folder,
that is the default setting of mongodb
and if you start a mongod instance without any additional setting, it will use that folder
but you can tell it to use another folder. And the same is true for the logs,
you can tell it to not output its log messages in the window where you started the mongod's instance
but instead into a separate file
and I want to do these two things. Now on Mac,
I can get the path to my db folder by clicking on it with a right click and then get info and then copying
that path, on windows in the explorer,
you can of course just copy that url by clicking into it once it becomes a full url and
then copying that.
And now if I want to start my mongodb server with that path being used, I can run sudo mongod
or on Windows, it would just be Mongod --dbpath like this,
then a blank
and then the path. And now important, I just copied the path to my mongodb folder,
of course I should point to the slash db folder, on windows its /db. Hit enter and enter your
password if you have to
And this should bring up your mongod server as it worked in the past but now you should see that in
the db folder, it created a bunch of files because now it's storing the data here and therefore this is
now using a totally different database storage than it previously did,
it's totally detached from our old database path,
we have a brand new database set up now because we're using a different file storage for the database
files. Now logging would also be interesting,
so let me quickly clear the window to make it easier to read,
let me quickly rerun sudo mongod here with db path
but I'll set an additional flag separated with a blank and then --logpath
and now I want to use almost the same path,
this one,
however it should be /logs and and that's important to know, the logs, the log path needs the path
to a log file,
so here you could add log.log for example. If you hit enter,
this now starts the server but you see way less output here because now if you look into logs, you should
have a log.log file,
now all the output gets written into that file
and that of course can be useful because now this file will get saved and you can always come back
to it,
check your logs from yesterday,
go through it,
see any warnings or errors you might have in there, like this warning that access control is not enabled
which is the default right now, we got no authentication,
we'll add it later.
So this can be useful for
well persist and error searching or for simply persistent and auditing of your server.
So this now is how you can set a custom path for your logs and how you can set a custom path for your
database. What else can we do?