Ref

Ref( schema_ref, document_id )
Ref( schema_ref, document_id )
Ref( schema_ref, document_id )
Ref( schema_ref, document_id )
ref( schema_ref, document_id )
Ref( schema_ref, document_id )

Description

The Ref function is used to express the reference for a specific document that exists in the current database, within the schema_ref, having the document ID id.

References serve the same purpose as primary keys in other database systems: they are used to provide a pointer to a specific document.

The schema_ref is a reference to a specific collection of documents. Everything in Fauna is described by a document. The documents that describe fundamental Fauna infrastructure are called schema documents, or core schemas. Any other documents are user-created, and are called user documents.

References to core schema documents, that you pass in via schema_ref, are provided by their respective functions:

The Ref function does not verify that the schema_ref, or the document_id within the schema_ref, exists. This means that you can use Ref to create a reference to a non-existent document in a non-existent collection.

This feature is particularly useful when creating parent-child relationships. The parent record can be created with a list of non-existent child references before the child records are created.

You have to use this feature carefully or queries that use such references could fail.

Parameters

Argument Type Definition and Requirements

schema_ref

A Reference to a specific schema document to which the desired document belongs.

document_id

A document identifier, which is a string-encoded 64-bit integer.

Returns

A reference to the document in the specified schema_ref that has the specified document_id.

Examples

The following query returns the reference to a specific document in the "spells" collection:

try
{
    Value result = await client.Query(
        Ref(Collection("spells"), "181388642046968320")
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
RefV(id = "181388642046968320", collection = RefV(id = "spells", collection = RefV(id = "collections")))
result, err := client.Query(
	f.Ref(f.Collection("spells"), "181388642046968320"))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{181388642046968320 0xc000160150 0xc000160150 <nil>}
System.out.println(
    client.query(
        Ref(Collection("spells"), "181388642046968320")
    ).get()
);
ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))
client.query(
  q.Ref(q.Collection('spells'), '181388642046968320')
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
Ref(Collection("spells"), "181388642046968320")
result = client.query(
  q.ref(q.collection("spells"), "181388642046968320")
)
print(result)
Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections)))
try {
  println(Await.result(
    client.query(
  Ref(Collection("spells"), "181388642046968320")
),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
ref(id = "181388642046968320", collection = ref(id = "spells", collection = ref(id = "collections")))

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!