How to restrict a mongo user from dropping a collection?

前端 未结 1 1840
醉话见心
醉话见心 2021-01-15 04:25

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?

相关标签:
1条回答
  • 2021-01-15 05:10

    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" }
          ]
        }
    )
    
    0 讨论(0)
提交回复
热议问题