create_row_policy()
Creates a row-level security policy on a collection.
pub async fn create_row_policy(&self, request: CreateRowPolicyRequest) -> Result<()>
Creating a policy with an existing name is an error. The caller must hold the ManageRLS privilege on the collection.
Request Syntax
let request = CreateRowPolicyRequest::builder()
.collection_name("books")
.policy_name("team_policy")
.policy_type(RowPolicyType::Permissive)
.actions([RowPolicyAction::Query, RowPolicyAction::Search])
.using_expr("team == $current_principal_tags['team']")
.build()?;
REQUEST FIELDS:
database_name: Option<String>Name of the target database; uses the default database when empty.
collection_name: StringName of the collection protected by the policy. Required.
policy_name: StringName of the policy. Required.
policy_type: RowPolicyTypeHow the policy combines with the collection’s other policies. Must be
PermissiveorRestrictive. See RowPolicyType.actions: Vec<RowPolicyAction>Operations governed by the policy. Must contain at least one unique action. See RowPolicyAction.
using_expr: StringExpression that filters rows for read and delete actions. At least one of
using_exprandcheck_expris required.check_expr: StringExpression that validates rows for insert and upsert actions. At least one of
using_exprandcheck_expris required.description: StringOptional description of the policy.
RETURN TYPE:
Result<()>
RETURNS:
Returns an empty result indicating success. Returns an Error if the request is invalid or the operation fails.
Example
let request = CreateRowPolicyRequest::builder()
.collection_name("books")
.policy_name("team_policy")
.policy_type(RowPolicyType::Permissive)
.actions([RowPolicyAction::Query, RowPolicyAction::Search])
.using_expr("team == $current_principal_tags['team']")
.build()?;
client.create_row_policy(request).await?;