use admin
db.createUser({user:"root",pwd:"xxx",roles:[{role:"root",db:"admin"}]})
db.createUser({user:"xxx",pwd:"xxx",roles:[{role:"readWrite",db:"xxx"}]})
----------繼續補充--------
mongodb啟用權限
查詢 db.system.users.find()
進入admin庫 use admin
創建root角色 db.createUser({user:"root",pwd:"xxxx",roles:["root"]})
認證 db.auth("root","xxxx")
查詢 db.system.users.find()
創建數據庫讀寫權限用戶
db.createUser({
user:'xx',
pwd:'xxxxxx',
customData:{description:"xxxx庫賬戶"},
roles:[{
'role':'readWrite',
'db':'xxx'
}]
})
插入數據才能顯示庫
db.runoob.insert({"name":"教程1111111111"})
創建庫 use xxx
查看庫 show dbs
查看所在庫 db
查看賬戶 show users
刪除用戶(需要root權限,會將所有數據庫中的football用戶刪除)
db.system.users.remove({user:"xxxx"})
刪除用戶(權限要求沒有那么高,只刪除本數據中的football用戶)
db.dropUser("xxx");
查看數據 show collections
參考https://www.cnblogs.com/out-of-memory/p/6810411.html