rolesInfo.roles vs rolesInfo.inheritedRoles

Hi!
I do not get the difference between two of them. Lectures do not explain this, manual is not clear for me.
Please give some examples.

Agree it’s not clear. It becomes a bit more clearer when you inherit user-defined roles. See the 3-step example below:

use admin
      
# 1. Create a role that inherits a built-in role
db.createRole(
   {
      role: "INHERIT_BUILTIN",
      privileges: [],
      roles: [
         {db: "test", role: "read"},
         {db: "test", role: "dbAdmin"}
      ]
   }
)

# 2. Create another role that inherits the custom role from (1)
db.createRole(
   {
      role: "INHERIT_CUSTOM",
      privileges: [],
      roles: [
         {db: "admin", role: "INHERIT_BUILTIN"}
      ]
   }
)

# 3. View roles info
db.getRoles()

However, note that the inherited roles is just a list, it doesn’t follow any logical order of inheritance.

1 Like