首页 > 解决方案 > 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>

标签: mongodb

解决方案


只有“backup”和“__system”可以操作这个表

db.system.keys.find()/count()       <====   "__system" role only
other operations (not verify all)   <====   "backup" and "__system" role

有没有人分享这个系列的细节。谢谢


推荐阅读