GrantPrivilege()
Grants a privilege on a resource to a role.
pub async fn grant_privilege(&self, request: GrantPrivilegeRequest) -> Result<()>
Collection-scoped grants use the v2 privilege RPC; grants configured with the legacy object_type/object_name surface (for example USER objects or explicit GLOBAL scope) use the v1 OperatePrivilege RPC. The two surfaces are mutually exclusive.
Request Syntax
let request = GrantPrivilegeRequest::builder()
.role_name("analyst")
.database_name("default")
.collection_name("books")
.privilege("Search")
.build()?;
REQUEST FIELDS:
role_name: StringName of the role receiving the privilege. Required.
database_name: StringDatabase that owns the target resource. Required.
collection_name: StringName of the collection the privilege applies to. Required unless the legacy
object_type/object_namesurface is used.privilege: StringName of the privilege to grant, for example
Search,Query, orInsert. Required.object_type: Option<String>Legacy v1 object type, for example
UserorGlobal. Must be paired withobject_name; mutually exclusive withcollection_name.object_name: Option<String>Legacy v1 object name. Must be paired with
object_type; mutually exclusive withcollection_name.
RETURN TYPE:
Result<()>
RETURNS:
Returns Ok(()) on success; returns an Error on failure.
Example
let request = GrantPrivilegeRequest::builder()
.role_name("analyst")
.database_name("default")
.collection_name("books")
.privilege("Search")
.build()?;
client.grant_privilege(request).await?;