MongoDB Tutorial 0/120 lessons ~6 min read Lesson 79
User Roles
MongoDB roles are privilege bundles attached to users.
Course progress0%
Focus
2 guided sections
Practice signal
Concept-first lesson
Career prep
Foundation builder
Introduction
MongoDB roles are privilege bundles attached to users. Apply the principle of least privilege: an app user should only have readWrite on the databases it needs.
Syntax reference
js
db.createRole({role: "ordersReader",privileges: [{ resource: { db: "shop", collection: "orders" }, actions: ["find"] }],roles: []});
Ready to mark this lesson complete?Track your journey across the entire course.