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

Product.where(.quantity < 10)
{
  data: [
    {
      id: "394786008151883842",
      coll: Product,
      ts: Time("2024-04-10T13:35:26.547Z"),
      name: "cups",
      description: "Translucent 9 Oz, 100 ct",
      price: 6.98,
      quantity: 90,
      store: Store("394786008147689538"),
      backorderLimit: 5,
      backordered: false
    },
    ...
    {
      id: "394786008166563906",
      coll: Product,
      ts: Time("2024-04-10T13:35:26.547Z"),
      name: "cilantro",
      description: "Organic, 1 bunch",
      price: 1.49,
      quantity: 95,
      store: Store("394786008145592386"),
      backorderLimit: 15,
      backordered: false
    }
  ]
}

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!