Mongodb Setup User and Password

Reading time ~1 minute

  1. start container with auth

     $ docker run --restart=always --name demo_db -itd -v /data/mongo/db:/data/db  -p 27017:27017 mongo:3 --auth
    
  2. login the database inside docker, user and pwd is unnecessary.

     $ docker exec -it demo_db /bin/sh
     $ mongo
    
  3. add user as admin

     //administrator db
     $ use admin
        
     // add user 'root'
     $ db.createUser({user: "root", pwd: "demo#$%!", roles: [ {role: "userAdminAnyDatabase", db: "admin"} ] })
    
  4. exit, and login with the user ‘root’ and pwd

     $ mongo -u "root" -p "demo#$%!" --authenticationDatabase "admin"
    
  5. authorize

     $ db.auth("root", "demo#$%!")
    
  6. add user for bussness db

     $ use test_db
    
     // add user for test_db and assign read and write permission
     $ db.createUser({user: "test", pwd: "Test", roles: [ { role: "readWrite", db: "test_db" } ]})
    
  7. exit and login with the new user and pwd

     $ mongo -u "test" -p "Test" --authenticationDatabase "test_db"
    
  8. authorize again

     $ use test_db
     $ db.auth("test", "Test")
    
  9. finish and quit.

  10. if using mongoose to access the encrypted db

    mongoose.connect('mongodb://username:[email protected]:port/database?options...');
    

Ubuntu install shadowsocks and switchyOmega

## 1. Install shadowsocks-qt5 GUI ```bash$ sudo add-apt-repository ppa:hzwhuang/ss-qt5$ sudo apt-get update$ sudo apt-get install shad...… Continue reading

CentOS upgrade to latest stable kernel

Published on January 18, 2018

pip设置国内镜像

Published on January 10, 2018