I recently tried enabling access control in MongoDB by following this this tutorial. However, when I reached the fourth step, MongoDB failed to start, showing this error:
{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to read metadata from /var/lib/mongo/storage.bson"}}
After troubleshooting, I found two issues and their solutions:
Usesudo: The mongod command must be run with sudo to avoid permission issues: sudo mongod --auth --port 27017 --dbpath /var/lib/mongodb
Directory name difference: On Fedora 41 (MongoDB 8.0.4 + Mongosh 2.3.9), the default directory is mongo, not mongodb
Some suggested modifying data and log directory persmissions, but simply using sudo resolves the issue.
I hope this helps others facing the same issue. Let me know if you have any questions or other solutions!
This is not recommend, mongod is now running as root. Ideally (and when installled via package manager) mongod will run under a dedicated non-privileged user.
The tutorial should really be updated to include starting with system utilites (systemctl).
Thanks for your feedback! I tried restarting mongod using systemctl, but it didn’t work. Without sudo, the only way I could restart it was by rebooting my system. However, after a reboot, the server started without access control enabled.
For reference, I used this tutorial to check how to manage MongoDB with systemctl.
Maybe the proper solution is to adjust the privileges of the mongo(db) directory instead. What do you think?