FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

Exists

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Exists( ref, [ts] )
exists( ref, [ts]
Exists( ref, [ts] )
Exists( ref, [ts] )
Exists( ref, [ts] )
Exists( ref, [ts] )

Description

The Exists function returns boolean true if the provided ref exists at the specified timestamp (in the case of a document), or is non-empty (in the case of a set), and false otherwise.

Parameters

Parameter Type Definition and Requirements

ref

Reference

The Reference that uniquely identifies a document within the database.

ts

Long or Timestamp

Optional - The timestamp at which the existence of the Reference is checked. Can be expressed as either a number of UNIX microseconds since epoch, or as a Timestamp. Defaults to the current time.

For large values of ts (positive or negative), you may need to express the value in a String to maintain numeric precision (Fauna uses 64-bit signed integers, whereas JavaScript uses 53-bit signed integers).

Returns

A boolean value

Examples

The following query checks for the existence of a ref pointing at a document in the spells collection at value 181388642046968320L. Since this ref is present at the current time, true is returned.

client.query(
  q.Exists(
    q.Ref(q.Collection('spells'), '181388642046968320')
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
true
result = client.query(
  q.exists(q.ref(q.collection("spells"), "181388642046968320"))
)
print(result)
True
result, err := client.Query(
	f.Exists(f.Ref(f.Collection("spells"), "181388642046968320")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
true
try
{
    Value result = await client.Query(
        Exists(Ref(Collection("spells"), "181388642046968320"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
BooleanV(True)
System.out.println(
    client.query(
        Exists(
            Ref(Collection("spells"), Value("181388642046968320"))
        )
    ).get());
true
Exists(
  Ref(Collection('spells'), '181388642046968320')
)
true
Query metrics:
  •    bytesIn:  68

  •   bytesOut:  17

  • computeOps:   1

  •    readOps:   1

  •   writeOps:   0

  •  readBytes: 112

  • writeBytes:   0

  •  queryTime: 4ms

  •    retries:   0

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!