在mongodb中,show users 和db.system.users.find() 都能查看账户的相关信息,但是这两个命令有什么区别么?
db.system.users.find() 是查看全局的所有账户
> use admin switched to db admin > db.system.users.find() { "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "+g1F+At5S9rC9fqIyHxDzA==", "storedKey" : "FOt1FE9+LqbcTQamwceQwULGJbY=", "serverKey" : "qZQWdSuYpH3E7k5GP30COrPqqZ8=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] } { "_id" : "demo.myuser", "user" : "myuser", "db" : "demo", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "rGTxEaSNry22EOFnjaAjAw==", "storedKey" : "/kWOpCEWm+iI/ESecqy2JkIXJFo=", "serverKey" : "A66NeaeGo8XhwgrKKeD0ASEN0Uc=" } }, "roles" : [ { "role" : "dbOwner", "db" : "mydb" }, { "role" : "readWrite", "db" : "mydb" } ] }
show users 是查看当前库下的账户
> use admin switched to db admin
> show users { "_id" : "admin.admin", "user" : "admin", "db" : "admin", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }