Exists

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

Argument Type Definition and Requirements

ref

The reference identifier within the database that uniquely identifies a document.

ts

Optional - The timestamp at which the existence of the ref 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 (FaunaDB 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(Exists(Ref(Collection("spells"), "181388642046968320")));
true
curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "exists": { "@ref": "classes/spells/181388642046968320" } }'
HTTP/1.1 200 OK
{ "resource": true }
result, _ := client.Query(
    f.Exists(f.RefCollection(f.Collection("spells"), "181388642046968320")),
)

fmt.Println(result)
true
System.out.println(
       client.query(
               Exists(Ref(
                       Collection("spells"),
                       Value(181388642046968320L)
                       )
               )
       ).get());
true
client.query(
  q.Exists(
    q.Ref(q.Collection('spells'), '181388642046968320')
  )
)
.then((ret) => console.log(ret))
true
client.query(q.exists(q.ref(q.collection("spells"), "181388642046968320")))
true
client.query(Exists(Ref(Collection("spells"), "181388642046968320")))
true

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!