MongoDB 檢視所有使用者賬號資訊
阿新 • • 發佈:2019-01-02
在 MongoDB 中建立了很多帳號,怎麼檢視所有帳號資訊?
檢視全域性所有賬戶 :
> use admin
switched to db admin
> db.auth('admin','123456')
1
> db.system.users.find().pretty()
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"credentials" : {
"SCRAM-SHA-1" : {
"iterationCount" : 10000,
"salt" : "******************==",
"storedKey" : "*****************=",
"serverKey" : "**************="
}
},
"roles" : [
{
"role" : "read",
"db" : "admin"
},
{
"role" : "readWrite",
"db" : "admin"
},
{
"role" : "dbAdmin",
"db" : "admin"
},
{
"role" : "userAdmin",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "readAnyDatabase" ,
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "hostManager",
"db" : "admin"
},
{
"role" : "clusterMonitor",
"db" : "admin"
},
{
"role" : "backup",
"db" : "admin"
},
{
"role" : "restore",
"db" : "admin"
},
{
"role" : "root",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "devicedb"
},
{
"role" : "readWrite",
"db" : "devicedb"
},
{
"role" : "userAdmin",
"db" : "devicedb"
},
{
"role" : "dbAdmin",
"db" : "devicedb"
}
]
}
{
"_id" : "test.test",
"user" : "test",
"db" : "test",
"credentials" : {
"SCRAM-SHA-1" : {
"iterationCount" : 10000,
"salt" : "******************==",
"storedKey" : "******************=",
"serverKey" : "******************="
}
},
"roles" : [
{
"role" : "read",
"db" : "test"
},
{
"role" : "readWrite",
"db" : "test"
},
{
"role" : "dbAdmin",
"db" : "test"
},
{
"role" : "userAdmin",
"db" : "test"
},
{
"role" : "dbOwner",
"db" : "test"
}
]
}
檢視當前庫下的賬戶 :
> use admin
switched to db admin
> show users
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "read",
"db" : "admin"
},
{
"role" : "readWrite",
"db" : "admin"
},
{
"role" : "dbAdmin",
"db" : "admin"
},
{
"role" : "userAdmin",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "readAnyDatabase",
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "hostManager",
"db" : "admin"
},
{
"role" : "clusterMonitor",
"db" : "admin"
},
{
"role" : "backup",
"db" : "admin"
},
{
"role" : "restore",
"db" : "admin"
},
{
"role" : "root",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "devicedb"
},
{
"role" : "readWrite",
"db" : "devicedb"
},
{
"role" : "userAdmin",
"db" : "devicedb"
},
{
"role" : "dbAdmin",
"db" : "devicedb"
}
]
}
> use test
switched to db test
> show users
{
"_id" : "test.test",
"user" : "test",
"db" : "test",
"roles" : [
{
"role" : "read",
"db" : "test"
},
{
"role" : "readWrite",
"db" : "test"
},
{
"role" : "dbAdmin",
"db" : "test"
},
{
"role" : "userAdmin",
"db" : "test"
},
{
"role" : "dbOwner",
"db" : "test"
}
]
}