OK, it all comes down to permissions, but let it take you step by step. When you run sudo mongod , it does not load the configuration file at all, it literally starts with the default compiled ones - port 27017 , the database path / data / db, etc. - thatβs why you got a message about the lack of the ability to find this folder. "Ubuntu default" is used only when you specify it in the configuration file (if you start using the utility command, this is done for you behind the scenes).
Then you run it like this:
sudo mongod -f /etc/mongodb.conf
If there were no problems before, then it will be - you started the process, with your usual configuration (pointing to your usual dbpath and log) as the root user. This means that in this regular MongoDB folder there will now be several files with the user: group root:root group.
This will lead to errors when trying to start it as a regular service again, because the mongodb user (which the service will try to execute as) will not get permission to access these root:root files, and most importantly, it probably wonβt be able to write to log file to provide you any information.
Therefore, to run it as a regular service, we need to fix these permissions. First, make sure MongoDB is not currently running as root, and then:
cd /var/log/mongodb sudo chown -R mongodb:mongodb . cd /var/lib/mongodb sudo chown -R mongodb:mongodb .
This should be fixed (assuming the user: mongodb:mongodb group mongodb:mongodb ), although it is probably best to check with ls -al or similar to be sure. Once this is done, you can start the service again.
Adam Comerford Sep 02 2018-12-12T00: 00Z
source share