Menu Docs

revogar privilégios da função

revokePrivilegesFromRole

Removes the specified privileges from the user-defined role on the database where the command is run.

Dica

Em mongosh, esse comando também pode ser executado por meio do método auxiliar db.revokePrivilegesFromRole().

Os métodos auxiliares são práticos para os usuários mongosh, mas podem não retornar o mesmo nível de informações que os comandos do banco de dados. Nos casos em que a praticidade não for necessária ou os campos de retorno adicionais forem necessários, use o comando de banco de dados.

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

  • MongoDB Atlas: o serviço totalmente gerenciado para implantações do MongoDB na nuvem

Importante

Esse comando não é suportado em clusters M0, M2, M5 e Flex. Para obter mais informações, 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

O comando tem a seguinte sintaxe:

db.runCommand(
{
revokePrivilegesFromRole: "<role>",
privileges: [
{ resource: { <resource> }, actions: [ "<action>", ... ] },
...
],
writeConcern: <write concern document>,
comment: <any>
}
)

O comando utiliza os seguintes campos:

Campo
Tipo
Descrição

revokePrivilegesFromRole

string

The user-defined role to revoke privileges from.

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.

comment

any

Opcional. Um comentário fornecido pelo usuário para anexar a este comando. Depois de definido, esse comentário aparece junto com os registros desse comando nos seguintes locais:

Um comentário pode ser qualquer tipo BSON válido (string, inteiro, objeto, array etc).

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, consider 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 cannot 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.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
resource : {
db : "products",
collection : "gadgets"
},
actions : [
"find",
"update"
]
}
]
}
)
db.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
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.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
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 in the products database:

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