where()

Get the set of matching accessible documents in the collection.

Signature

where(predicate: () => Boolean)): Set<Collection>

where(predicate: (val: Document) => Boolean)): Set<Collection>

Description

Gets the set of accessible document in the collection that match the predicate function.

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

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous function that compares values in each collection document and returns true for matches or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Document

Document object to compare. If omitted, use dot notation to access document properties.

Return value

Type Description

Set<Document>

Set of matching accessible documents.

Examples

Letter.where(.name < 'C')
{
  data: [
    {
      id: "357101835888099361",
      coll: Letter,
      ts: Time("2023-02-19T14:41:39.230Z"),
      name: "A"
    },
    {
      id: "357101842659803169",
      coll: Letter,
      ts: Time("2023-02-19T14:41:45.693Z"),
      name: "B"
    }
  ]
}

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!