Slight modification to this @CodeMaker 's answer, for anyone like me who is trying to modify a MongoDB service to use authentication.
When I looked at the "Path to executable" in "Services" the executed line already contained speech marks. So I had to make minor modification to his example.
To be specific.
For me the path was (note the speech marks)
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\4.2\bin\mongod.cfg" --service
In a command line type
sc config MongoDB binPath= "<Modified string with \" to replace ">"
In my case this was
sc config MongoDB binPath= "\"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe\" --config \"C:\Program Files\MongoDB\Server\4.2\bin\mongod.cfg\" --service -- auth"