MongoDB's authorization model is built on Role-Based Access Control (RBAC). The hierarchy is: User → Roles → Privileges → (Resource + Actions). A user has no direct privileges — only the sum of privileges from all assigned roles.
- Resource: a specific database, collection, cluster, or any combination
- Action: a specific operation allowed on a resource (e.g.,
find,insert,dropCollection) - Privilege: one resource + one or more actions
- Role: a named collection of privileges (optionally inheriting from other roles)
// Conceptual structure of a role: { role: "orderManager", db: "shopDb", privileges: [ { resource: { db: "shopDb", collection: "orders" }, actions: ["find", "insert", "update"] }, { resource: { db: "shopDb", collection: "customers" }, actions: ["find"] } ], roles: ["read"] // inherits all privileges from built-in "read" role } // Principle of least privilege: grant ONLY what the user needs // An application user should NEVER have clusterAdmin, root, or userAdminAnyDatabase