mongodb增加auth

mongo

db.createCollection(‘demodb’)

create super user

db.createUser(
  {
    user: "user",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

create app user

mongo --port 27017 -u "user" -p "password" --authenticationDatabase "admin"
use demodb
db.createUser(
  {
    user: "demo",
    pwd: "demopwd",
    roles: [ { role: "readWrite", db: "demodb" } ]
  }
)
exit
mongo -u demo -p demopwd --authenticationDatabase demodb
use demodb
db.getCollection('yourcollection').find()

开启验证

/usr/bin/mongod --auth -f /etc/mongod.conf

docs

    原文作者:codecraft
    原文地址: https://segmentfault.com/a/1190000007136083
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞