mongodb进行操作时,出现errmsg" : "not authorized on test to execute command { listCollections: 1.0 }这个提示
表示没有权限,那就赶紧添加用户吧
切换到admin库
use admin;
添加用户
db.createUser( {
user: "sa",
pwd: "sa",
roles: [ { role: "root", db: "admin" } ]
});
既然已经添加了用户
用sa账号登录
db.auth('sa','sa');
再执行以前的命令,是否还会出现
errmsg" : "not authorized on test to execute command { listCollections: 1.0 }