Menu Docs

db.revokePrivilegesFromRole()

db.revokePrivilegesFromRole(rolename, privileges, writeConcern)

Removes the specified privileges from the user-defined role on the database where the method runs.

Importante

Método mongosh

Esta página documenta um método mongosh. Esta não é a documentação para comandos de banco de dados nem drivers específicos de linguagem, como Node.js.

Para o comando do banco de dados, consulte o comando revokePrivilegesFromRole.

Para drivers de API do MongoDB, consulte a documentação do driver do MongoDB específica da linguagem.

O método db.revokePrivilegesFromRole() tem a seguinte sintaxe:

db.revokePrivilegesFromRole(
"<rolename>",
[
{ resource: { <resource> }, actions: [ "<action>", ... ] },
...
],
{ <writeConcern> }
)

O método db.revokePrivilegesFromRole() utiliza os seguintes argumentos:

Parâmetro
Tipo
Descrição

rolename

string

The name of the user-defined role from which to revoke privileges.

privileges

array

An array of privileges to remove from the role. See privileges for more information on the format of the privileges.

writeConcern

documento

Opcional. O nível da write concern para a operação. Consulte Especificação de write concern.

Esse método está disponível em implantações hospedadas nos seguintes ambientes:

Importante

Este comando não é suportado em clusters MongoDB Atlas . Para obter informações sobre o suporte do Atlas para todos os comandos, consulte Comandos não suportados.

  • MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB

  • MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB

Se executado em um conjunto de réplicas, db.revokePrivilegesFromRole() é executado usando a preocupação de gravação "majority" por padrão.

To revoke a privilege, the resource document pattern must match exactly the resource field of that privilege. The actions field can be a subset or match exactly.

For example, given the role accountRole in the products database with the following privilege that specifies the products database as the resource:

{
"resource" : {
"db" : "products",
"collection" : ""
},
"actions" : [
"find",
"update"
]
}

You não pode revoke find and/or update from just one collection in the products database. The following operations result in no change to the role:

use products
db.revokePrivilegesFromRole(
"accountRole",
[
{
resource : {
db : "products",
collection : "gadgets"
},
actions : [
"find",
"update"
]
}
]
)
db.revokePrivilegesFromRole(
"accountRole",
[
{
resource : {
db : "products",
collection : "gadgets"
},
actions : [
"find"
]
}
]
)

To revoke the "find" and/or the "update" action from the role accountRole, you must match the resource document exactly. For example, the following operation revokes just the "find" action from the existing privilege.

use products
db.revokePrivilegesFromRole(
"accountRole",
[
{
resource : {
db : "products",
collection : ""
},
actions : [
"find"
]
}
]
)

You must have the revokeRole ação on the database a privilege targets in order to revoke that privilege. If the privilege targets multiple databases or the cluster resource, you must have the revokeRole action on the admin database.

The following operation removes multiple privileges from the associates role:

db.revokePrivilegesFromRole(
"associate",
[
{
resource: { db: "products", collection: "" },
actions: [ "createCollection", "createIndex", "find" ]
},
{
resource: { db: "products", collection: "orders" },
actions: [ "insert" ]
}
],
{ w: "majority" }
)