如何限制mongo用户删除集合? [英] How to restrict a mongo user from dropping a collection?

查看:100
本文介绍了如何限制mongo用户删除集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MongoDB中创建可应用于用户的角色的配置/命令是什么?

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?

推荐答案

检查mongoDB文档以创建用户角色和权限. http://docs.mongodb.org/manual/tutorial/manage-用户和角色/

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

通常,对于非管理员角色,仅提供read访问权限将阻止用户删除集合.下面的代码取自mongo文档,并演示了对各种集合的访问权限修改.

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" }
      ]
    }
)

这篇关于如何限制mongo用户删除集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆