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)
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-authorized


Warning/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. 

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

  • 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

Popular posts from this blog

UI-Bootstrap Collapsible Sticky Footer

Installing Windows on Acer chromebook 15 cb3-532

Aspetcore: NLog with Postgresql