Role.where()

Get the set of accessible Roles in the database.

Signature

Role.where(predicate: () => Boolean)): Set<Role>

Role.where(predicate: (val: Role) => Boolean)): Set<Role>

Description

Each Role in a Fauna database is represented by a Role object. The Role.where() method gets the set of accessible roles that match the predicate function.

If Role.where() is the last value in a query, the first page of the Set is returned.

Parameters

Parameter Type Required Description

predicate

Function

Yes

An anonymous function that compares values in each document and returns true for matching roles or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Role

Role document to compare. If omitted, use dot notation to access role properties.

Return value

One of:

Type Description

Set<Role>

Set representing the roles that match the predicate function.

Null

When no roles matches.

Examples

Role.where(.name.includes("manager"))
{
  data: [
    {
      name: "manager",
      coll: Role,
      ts: Time("2023-07-21T00:22:25.260Z"),
      privileges: [
        {
          resource: "Store",
          actions: {
            create: true,
            read: true,
            write: true,
            delete: true
          }
        },
        ...
        {
          resource: "Manager",
          actions: {
            read: "(ref) => Query.identity() == ref"
          }
        }
      ],
      membership: [
        {
          resource: "Manager"
        }
      ]
    }
  ]
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!