getUser(username, { showPrivileges?, showCredentials? }?)
This method returns user information for a specified user. Run this method on the user’s database.
Note:
The user must exist in the database on which the method runs.
Syntax:
db.getUser(username, { showPrivileges?, showCredentials? }?)
Example 1: When showPreviliges and showCredentials not present.
use admin
db.getUser("dbUser")
MongoDB
db.getUser("dbUser")
Output:
{"_id" : "test.dbUser","userId" : UUID("4a722cfc-cd31-40a3-a4dd-410b7bc86d70"),"user" : "dbUser","db" : "test","roles" : [{"role" : "dbAdmin","db" : "test"},{"role" : "readWrite","db" : "test"}],"mechanisms" : ["SCRAM-SHA-1","SCRAM-SHA-256"]}
Example 2: When showPreviliges and showCredentials are present.
db.getUser("dbUser", { showPrivileges:true, showCredentials:true })
MongoDB
db.getUser("dbUser", { showPrivileges:true, showCredentials:true })
Output:
{"_id" : "test.dbUser","userId" : UUID("4a722cfc-cd31-40a3-a4dd-410b7bc86d70"),"user" : "dbUser","db" : "test","mechanisms" : ["SCRAM-SHA-1","SCRAM-SHA-256"],"credentials" : {"SCRAM-SHA-1" : {"iterationCount" : 10000,"salt" : "kQBGbXMN55QQ5XPJFxKj/g==","storedKey" : "SfOh4giJr0fZMp6Y7YFuE9pGjQY=","serverKey" : "86ZjppgA6YBg4KcUFJi3g1CDSfQ="},"SCRAM-SHA-256" : {"iterationCount" : 15000,"salt" : "hUn8Q1UBzbdbp2HqMI6quMooT0Ba+j2WJqKoFQ==","storedKey" : "2I+aF/dqiXfShQeetrcqa8L2daRtJt1gRGHi6C+yuEs=","serverKey" : "hHU86IOBAg9m2mvTB74c6iwJ58dmnD04ozFTEpbKqFg="}},"roles" : [{"role" : "dbAdmin","db" : "test"},{"role" : "readWrite","db" : "test"}],"inheritedRoles" : [{"role" : "readWrite","db" : "test"},{"role" : "dbAdmin","db" : "test"}],"inheritedPrivileges" : [{"resource" : {"db" : "test","collection" : ""},"actions" : ["bypassDocumentValidation","changeStream","collMod","collStats","compact","convertToCapped","createCollection","createIndex","dbHash","dbStats","dropCollection","dropDatabase","dropIndex","emptycapped","enableProfiler","find","insert","killCursors","listCollections","listIndexes","planCacheIndexFilter","planCacheRead","planCacheWrite","reIndex","remove","renameCollectionSameDB","storageDetails","update","validate"]},{"resource" : {"db" : "test","collection" : "system.js"},"actions" : ["changeStream","collStats","convertToCapped","createCollection","createIndex","dbHash","dbStats","dropCollection","dropIndex","emptycapped","find","insert","killCursors","listCollections","listIndexes","planCacheRead","remove","renameCollectionSameDB","update"]},{"resource" : {"db" : "test","collection" : "system.profile"},"actions" : ["changeStream","collStats","convertToCapped","createCollection","dbHash","dbStats","dropCollection","find","killCursors","listCollections","listIndexes","planCacheRead"]}],"inheritedAuthenticationRestrictions" : [ ]}
Example 3: When showPreviliges is present.
db.getUser("dbUser", { showPrivileges:true})
MongoDB
db.getUser("dbUser", { showPrivileges:true })
Output:
{"_id" : "test.dbUser","userId" : UUID("4a722cfc-cd31-40a3-a4dd-410b7bc86d70"),"user" : "dbUser","db" : "test","mechanisms" : ["SCRAM-SHA-1","SCRAM-SHA-256"],"roles" : [{"role" : "dbAdmin","db" : "test"},{"role" : "readWrite","db" : "test"}],"inheritedRoles" : [{"role" : "readWrite","db" : "test"},{"role" : "dbAdmin","db" : "test"}],"inheritedPrivileges" : [{"resource" : {"db" : "test","collection" : ""},"actions" : ["bypassDocumentValidation","changeStream","collMod","collStats","compact","convertToCapped","createCollection","createIndex","dbHash","dbStats","dropCollection","dropDatabase","dropIndex","emptycapped","enableProfiler","find","insert","killCursors","listCollections","listIndexes","planCacheIndexFilter","planCacheRead","planCacheWrite","reIndex","remove","renameCollectionSameDB","storageDetails","update","validate"]},{"resource" : {"db" : "test","collection" : "system.profile"},"actions" : ["changeStream","collStats","convertToCapped","createCollection","dbHash","dbStats","dropCollection","find","killCursors","listCollections","listIndexes","planCacheRead"]},{"resource" : {"db" : "test","collection" : "system.js"},"actions" : ["changeStream","collStats","convertToCapped","createCollection","createIndex","dbHash","dbStats","dropCollection","dropIndex","emptycapped","find","insert","killCursors","listCollections","listIndexes","planCacheRead","remove","renameCollectionSameDB","update"]}],"inheritedAuthenticationRestrictions" : [ ]}
No comments:
Post a Comment