mongodb - Failed to execute db.system.keys.find() via root, how can this collection be find()?
问题描述
MongoDB version is 4.0.3
Root user has been created via
db.createUser({user:"root",pwd:"arthur",roles:[{role:"root",db:"admin"}]})
Via listCollections or db.getCollectionInfos(), three collections as list,
system.users
system.version
system.keys
'Not authorized' info would be shown when find() on system.keys. And another two collections are without any error.
I'm not sure anything missing/wrong for user creation or others. How can I handle this error. Look forward to your help.
How can I get details about this collection which is not mentioned in document https://docs.mongodb.com/manual/reference/system-collections/
Console print as below
MongoDB Enterprise mongos> use admin
switched to db admin
MongoDB Enterprise mongos> db.auth("root","arthur")
1
MongoDB Enterprise mongos> db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )
{
"cursor" : {
"id" : NumberLong(0),
"ns" : "admin.$cmd.listCollections",
"firstBatch" : [ ]
},
"ok" : 1,
"operationTime" : Timestamp(1541747273, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1541747273, 1),
"signature" : {
"hash" : BinData(0,"FnDH1ejRM/2TfV+0WiPFqH0KIMk="),
"keyId" : NumberLong("6621746286506803230")
}
}
}
MongoDB Enterprise mongos> db.runCommand( { listCollections: 1.0, nameOnly: true } )
{
"cursor" : {
"id" : NumberLong(0),
"ns" : "admin.$cmd.listCollections",
"firstBatch" : [
{
"name" : "system.users",
"type" : "collection"
},
{
"name" : "system.version",
"type" : "collection"
},
{
"name" : "system.keys",
"type" : "collection"
}
]
},
"ok" : 1,
"operationTime" : Timestamp(1541747273, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1541747273, 1),
"signature" : {
"hash" : BinData(0,"FnDH1ejRM/2TfV+0WiPFqH0KIMk="),
"keyId" : NumberLong("6621746286506803230")
}
}
}
MongoDB Enterprise mongos> db.system.keys.find()
Error: error: {
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { find: \"system.keys\", filter: {}, lsid: { id: UUID(\"a7884ca5-0f46-4906-8a15-955bbd74d2ae\") }, $clusterTime: { clusterTime: Timestamp(1541747273, 1), signature: { hash: BinData(0, 1670C7D5E8D133FD937D5FB45A23C5A87D0A20C9), keyId: 6621746286506803230 } }, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized",
"operationTime" : Timestamp(1541747273, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1541747273, 1),
"signature" : {
"hash" : BinData(0,"FnDH1ejRM/2TfV+0WiPFqH0KIMk="),
"keyId" : NumberLong("6621746286506803230")
}
}
}
MongoDB Enterprise mongos>
解决方案
只有“backup”和“__system”可以操作这个表
db.system.keys.find()/count() <==== "__system" role only
other operations (not verify all) <==== "backup" and "__system" role
有没有人分享这个系列的细节。谢谢
推荐阅读
- mysql - 平面表上的 mySQL 包容性搜索
- html - 表格行的css box-shadow?
- sql - 向现有表添加复合键
- javascript - PHP 和基本身份验证
- angular - 将数据从 Angular 应用程序中的 main.ts 文件传递给服务
- apache-nifi - 启动 NIFI 时 .. 出现异常:java.nio.file.FileSystemException:./state/local/partition-0/107654.journal:打开的文件太多
- mysql - 为什么连接测试失败?
- javascript - 如何修复 SlickNav 未初始化
- javascript - 如果后续的承诺将根据条件返回,如何使用承诺链?
- python - 仅在没有 linter 错误的情况下配置 VS Code 以执行 Python 脚本