MongoDB all Error Solutions
MongoDB all Error Solutions
How to secure MongoDB with username and password
-
start mongo shell by typing
mongo
in terminal. -
use admin database:
use admin
- create a new user and assign your intended role:
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: passwordPrompt(), // or cleartext password
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
- exit mongo and add the following line to
etc/mongod.conf
:
security:
authorization: enabled
- restart mongodb server
(optional) 6.If you want your user to have root access you can either specify it when creating your user like:
db.createUser(
{
user: "myUserAdmin",
pwd: passwordPrompt(), // or cleartext password
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
or you can change user role using:
db.auth("myUserAdmin", "abc123")
db.grantRolesToUser('myUserAdmin', [{ role: 'root', db: 'admin' }])
------------------------------------------
MongoDB loads but breaks, returning status=14
Solution 1 :
fter googling around for a while. I found that that is because the permission settings on /var/lib/mongodb
and /tmp/mongodb-27017.lock
are wrong. You will have to change the owner to monogdb user
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
then
sudo systemctl restart mongod
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
Solution 2:
deleting the mongod sock file solved the issue for me sudo rm -rf /tmp/mongodb-27017.sock
then start again sudo systemctl start mongod
or
By using this my error was gone:
- Go to the
TMP
directory:cd /tmp
- Check if you have the mongodb sock file:
ls *.sock
- Change the user:group permission:
chown mongodb:mongodb
- Start MongoDB:
sudo systemctl start mongod
- Check the MongoDB status:
sudo systemctl status mongod
Related Posts:
- How To Setup LVS (Linux Virtual Server) Load Balancer on Rocky Linux 8.5
- How To Install Magento 2.4 on Rocky Linux 8
- How To Install Docker on Oracle Linux Server 9
- How to Install WHM/cPanel in Almalinux?
- How To Install Ruby on Rails with PostgreSQL on Rocky Linux 8
- How To Install EMQX MQTT Broker on Rocky Linux 8
- How To Install Kamailio SIP Server on Rocky Linux 8
- How to Install and Configure RabbitMQ Server on Rocky Linux 8
- Setup Quick DNS Server On Rocky Linux 8.5 Using Dnsmasq
- 2 Ways To install Ruby On Rocky Linux | RVM
Latest Posts
- Server-Side Scripting: PHP, Node.js, Python – A Detailed Comparison
- Securing Your Website in 2024: Essential Strategies for Online Safety
- The Future of Web Development Technologies: Trends to Watch in 2024
- How Banks Handle Server-Side Operations and Ensure System Security: An Inside Look
- Tips for Writing Clean, Understandable, and Efficient Code: Avoiding Garbage Code
- Tailwind CSS: Revolutionizing Modern Web Design
- Basic Linux Commands for Beginners: A Starter Guide
- Dairy Farming Loan Apply
- BSNL Recharge Plan
- Bijli Bill Mafi Yojana Online Apply
Technical
- DevOps Roadmap
- How To Install and Configure an SNMP on Ubuntu 20.04
- Apple releases iOS 18 Developer Beta 2 with iPhone screen mirroring, RCS toggle,and more
- How to enable SNMP on Ubuntu Linux 18.04 and above
- How to Force HTTPS Using .htaccess (Updated 2024)
- Display All PHP Errors: Basic & Advanced Usage
- PHP alert
- MongoDB loads but breaks, returning status=14
- MongoDB database deleted automatically
- MongoDB all Error Solutions
Category