我在 mongoshell 中使用以下命令创建了一个默认管理员用户:
use admin
db.createUser(
{
user: "root",
pwd: "root",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
然后我使用 shell 和我的凭据进行身份验证,如下所示:
mongo --port 27017 -u "root" -p "root" --authenticationDatabase "admin"
在 shell 中,我可以看到
users
和 version
集合使用:> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test 0.000GB
> use admin
switched to db admin
> show tables
system.users
system.version
>
现在,当我尝试从 MongoDB Compass Community 访问这些表时,我首先进行身份验证:
现在管理数据库显示为空?
我如何才能像从 shell 一样从图形界面访问用户集合和其他集合?
最佳答案
看不到用户集合和其他集合的原因是 userAdminAnyDatabase 内置角色。默认情况下,它不需要必要的权限来读取这些集合。
根据您的需要尝试 root 或 dbAdminAnyDatabase。
干杯,
资源:
https://docs.mongodb.com/manual/reference/built-in-roles/
关于MongoDB 指南针社区 : Databases are visible but their collections are not showing up after authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62087007/