An innocent “tab” indentation in the mongod.cfg file fails to startup the database, Why?

I was baffled, I could not see any difference between the (2) mongod.cfg files I was playing with. One would work, the other would not.

To the naked eye, the only difference was an extra line. Could the startup process be so delicate and so flimsy that an innocent extra line could cause a failure to start up the mongodb database? Apparently so.

After further examining that innocent extra line in the mongod.cfg file, I found I had pressed the “tab” key, so if I kept the extra line in, but with no “tab” indentation in the line, I could successfully startup the mongodb database. However, put that “tab” in the extra blank line, it fails to startup mondodb.

I am baffled, how easily this can happen. 4 hours ago I made a change to the mongod.cfg file according to the online manual at https://docs.mongodb.com/manual/tutorial/enable-authentication/, and then it did not work.

Well I proceeded to backout line by line and trying with no success, until I was down to the only difference between the mongod.cfg that worked and the mongod.cfg the did NOT work was an extra line with a “tab” indentation that is not visible to the naked eye.

Question:
What is wrong with the mongo configuration reader that it cannot handle and extra “tab” in a line?

See my attached two mongod.cfg files


#1. mongod.cfg <— that works
#2. mongod.cfg <— that does not work with one extra blank line. See line number 12. Mongodb supplies no log messages in an empty mongod.log to analyze. It fails hard and fast.

Mongodb version 4.4.0
Windows 10 pro 64bit
Editor windows Notepad++

The mongo config format is YAML . It would have to pass as valid syntax.
Because your config is invalid the file logger would not have initialised.

If invoking mongod on the command line there would likely have been an error along the lines of:

mongod -f mongod.conf
Error parsing YAML config file: yaml-cpp: error at line 8, column 10: illegal map value
try ‘mongod --help’ for more information

As you are on windows I’ll go ahead and assume this is being logged in event viewer as the Service Control Manager is starting and stopping mongod if you installed as a service.

1 Like

Thanks, Chris, for your quick response.
I did not know it was a YAML file based on the suffix “mongod.cfg”
But it makes sense, I validated my mongod.cfg file with an extra line and tab in it at http://www.yamllint.com/
And it does not pass:
(): found a tab character that violate intendation while scanning a plain scalar at line 11 column 14

I am not used to working with YAML files.
YAML files are so well indented to be readable (but … in YAML, you indent with spaces, not tabs, in addition, there MUST be spaces between element parts.)
I guess YAML files are more readable, but the con is they are harder to type up or change them, you need a linter or compiler to get the syntax correctly typed up.

I will use the linter to validate the file if I make more changes.
I am running the zip installation on windows. Starting mongod.exe up with a *.bat file which points to the mongod.cfg file.

Thanks again,
Wally

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.