How do mongodb handles configuration from configuration file and shell helper

Hi,

I am really having a bit of a hard time wrapping my mind around how MongoDB uses the configuration file and the shell helper commands when it comes to configuration.

My understanding thus far is: the configuration file is a way of documenting the parameters we need to start the server/topology, and the great advantage they offer is their reusability. The shell helper commands allow us to do the configuration on the fly, however the configuration does not persist in case the db process is restarted.

My question is, where are these configuration stored within mongodb once the server is started, is there a special collection to hold them?

And, When changing the topology using the mongo shell, like in the lecture, I assume we loose all of them if something goes wrong with the server. So, should we edit the config file and restart the mongodb process (to reload them)?

Hi @Euclides_04014,

Yes, you are right here. The configuration file contains settings that are equivalent to the mongod and mongos command-line options.

My understanding thus far is: the configuration file is a way of documenting the parameters we need to start the server/topology, and the great advantage they offer is their reusability. The shell helper commands allow us to do the configuration on the fly, however the configuration does not persist in case the db process is restarted.

As an answer to your question, the MongoDB shell is not something to store configuration in firstly.
It is an interactive JavaScript interface to MongoDB and can act upon the mongod but it should really be seen as a highly customized UI/driver combination.
It is in essence the pre-GUI/command line alternative to Compass.

If you need to change a setting use a command via the Mongo Shell or equally via one of the drivers. The details are in the local DB which they should explicitly not edit or update in any way. https://docs.mongodb.com/manual/reference/local-database/

As far as the durability of config file is concerned, it will persist between restarts so that’s exactly where permanent changes should be stored in terms of configuration.
The Mongo Shell will make changes to the running mongod which when restarted will only reflect what is in the config file.

Please feel free to ask if you have any further queries, happy learning!

Thanks,
Muskan
Curriculum Support Engineer

1 Like