แสดง User ทั้งหมด 2 วิธี
วิธีที่ 1: ใช้ getUsers()
db.getUsers();
วิธีที่ 2: ใช้ show users
show users;
ตัวอย่างผลลัพธ์ getUsers()
[
{ "_id" : "test.John", "user" : "John", "db" : "test", "roles" : [ { "role" : "readWrite", "db" : "test" }, { "role" : "dbAdmin", "db" : "test" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] },
{ "_id" : "test.admin", "user" : "admin", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
]
ตัวอย่างผลลัพธ์ show users
{ "_id" : "test.John", "user" : "John", "db" : "test", "roles" : [ { "role" : "readWrite", "db" : "test" }, { "role" : "dbAdmin", "db" : "test" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
{ "_id" : "test.admin", "user" : "admin", "db" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
ทั้งสองคำสั่งแสดงข้อมูล User, Role และ Authentication Mechanism เหมือนกัน แต่รูปแบบต่างกันเล็กน้อย