Mongodb Cheatsheet
This cheat sheet is based on the latest version of mongodb, which initial had setup and didn't encounter any problems. However that all changed when I was working remote and forgot I disabled the port no my network, rather than with the server. So I went pointing around where I didn't need to and ended up messing things up. The Best tutorial out there is of course on digital ocean for my setup on ubuntu 16.04, this articles isn't so much about getting setup. I just wanted to include it because I found myself looking back at it to see if I missed a step.
Bugs/Problems
Now comes all the messed up things I found and had to deal with.
If you issue starts with this config, (Can't connect to MongoDB with authentication enabled)
Warning/Error (Assertion: 28595:13: Permission denied)
The Finale
After all this I was back up and turned out to be a mix multiple things, I be sure to look out for more when I split my database up. Side note IDE's I am using because I haven't figured out which one I like more are Robo 3T, mongobooster.
Commands of Importance
Bugs/Problems
Now comes all the messed up things I found and had to deal with.
- firewall - Port seems to be open, but connection refused
- try using 0.0.0.0 in the bin_ip for the /etc/mongo.conf
- try sudo ufw disable and check to see if it works without the firewall (probably still wont but worth a shot), then just sudo ufw enable. Make sure port 27017 is open.
- Then check this linux - Connection refused to MongoDB errno 111
If you issue starts with this config, (Can't connect to MongoDB with authentication enabled)
security:
authorization: enabled
Start by looking at the user you are using, try adding using root and not the documentation's use of the userAdminAnyDatabase.use admin
db.createUser(
{
user: "admin",
pwd: "password",
roles: [ { role: "root", db: "admin" } ]
}
);
exit;
- mongodb-admin-user-not-authorizedWarning/Error (Assertion: 28595:13: Permission denied)
# storage.dbPath
sudo chown -R mongodb:mongodb /var/lib/mongodb
# systemLog.path
sudo chown -R mongodb:mongodb /var/log/mongodb
Similar issue with:
"MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating". I added the bit for my machine to do this to the folder where my data was, /data/db. Note I'm not sure if you need to worry about this warnings I just was stuck and pick straws with what the issue was.
Commands of Importance
- mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
- db.changeUserPassword("accountUser", "password")
- db.getUsers()
- For a clean install,
- sudo apt-get purge mongodb-org*
- sudo apt-get autoremove
- sudo rm -r /var/log/mongodb
- sudo rm -r /var/lib/mongodb