Unauthorized: not authorized on admin to execute command

Successfully authenticated as principal admin on admin from client 127.0.0.1:52564
Unauthorized: not authorized on admin to execute command { getLog: "startupWarnings" }
Unauthorized: not authorized on admin to execute command { getCmdLineOpts: 1.0 }
Unauthorized: not authorized on admin to execute command { replSetGetStatus: 1.0, forShell: 1.0 }

db.grantRolesToUser("admin",[{role:"read", db:"admin"},{role:"readWrite",db:"admin"},{role:"dbAdmin", db:"admin"},{role:"userAdmin",db:"admin"}]);

db.grantRolesToUser("admin",[{role: "clusterMonitor", db:"admin"},{role: "clusterAdmin", db:"admin"}]);

Unauthorized: not authorized on admin to execute command_第1张图片

Microsoft Windows [版本 10.0.19045.2965]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Administrator>d:

D:\>
D:\>cd D:\MongoDB\Server\3.4\bin

D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>mongo --port 27017 -u "admin" -p "123456" --authenticationDatabase "admin"
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.24
>
>
> use admin
switched to db admin
>
>
> db.grantRolesToUser("admin",[{role:"read", db:"admin"},{role:"readWrite",db:"admin"},{role:"dbAdmin", db:"admin"},{role:"userAdmin",db:"admin"}]);
>
>
> exit;

D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>mongo --port 27017 -u "admin" -p "123456" --authenticationDatabase "admin"
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.24
>
>
> exit;

D:\MongoDB\Server\3.4\bin>mongo --port 27017 -u "admin" -p "123456" --authenticationDatabase "admin"
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.24
>
>
> use admin
switched to db admin
>
>
> db.grantRolesToUser("admin",[{role: "clusterMonitor", db:"admin"},{role: "clusterAdmin", db:"admin"}]);
>
> exit;

D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>
D:\MongoDB\Server\3.4\bin>mongo --port 27017 -u "admin" -p "123456" --authenticationDatabase "admin"
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.24
>
>

Unauthorized: not authorized on admin to execute command_第2张图片

虽然上面我执行了两个授权,实际上是因为

db.grantRolesToUser("admin",[{role: "clusterMonitor", db:"admin"},{role: "clusterAdmin", db:"admin"}]);

WARNING: Access control is not enabled for the database.-CSDN博客

你可能感兴趣的:(MongoDB,mongodb)