MongoDB中设置权限之后,如果再使用一般的命令都会报"$err" : "not authorized for query on admin.system.namespaces"这个错误,其意思就是没有权限,无法进行操作.则可以如下解决:
假设之前设置的用户为root,密码为admin
> use admin
switched to db admin
> db.addUser("root","admin")
{
"user" : "root",
"readOnly" : false,
"pwd" : "bde0d84f6749c235a6b4e36d945eb666",
"_id" : ObjectId("515e662430d89f61f6991c91")
}
> show collections
Fri Apr 05 13:50:36.685 JavaScript execution failed: error: {
"$err" : "not authorized for query on admin.system.namespaces",
"code" : 16550
} at src/mongo/shell/query.js:L128
>
说明:使用以上指令show collections的时候,发现报错了。是因为没有权限。做如下操作:
验证当前用户:
> db.auth("root","admin");
1
说明:返回1表示验证成功了,返回0表示验证失败。
此时,输入以下指令:show collections则可以看到admin下的集合了。
> show collections
system.indexes
system.users