Shubham Sharma
Shubham Sharma

Reputation: 43

How to restrict a mongo user from dropping a collection?

What would be the configuration/command for creating a role which can be applied to a user in MongoDB so that the user is unable to drop a collection?

Upvotes: 2

Views: 2691

Answers (1)

snozza
snozza

Reputation: 2253

Check the mongoDB documentation for creating user roles and privileges. http://docs.mongodb.org/manual/tutorial/manage-users-and-roles/

In general, for a non-admin role, only providing read access will prevent a user from dropping a collection. The code below is taken from the mongo docs and demonstrates access modifications for various collections.

use reporting
db.createUser(
    {
      user: "reportsUser",
      pwd: "12345678",
      roles: [
         { role: "read", db: "reporting" },
         { role: "read", db: "products" },
         { role: "read", db: "sales" },
         { role: "readWrite", db: "accounts" }
      ]
    }
)

Upvotes: 5

Related Questions