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

For more details, review the migration guide. Contact support@fauna.com with any questions.

Singleton

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

Singleton( ref )
singleton( ref )
Singleton( ref )
Singleton( ref )
Singleton( ref )

Description

The Singleton function produces a set containing the Reference that you provide.

In most cases, functions cast References into sets when necessary. The only case where Singleton is required is to return a set’s events rather than a Reference’s events.

Parameters

Parameter Type Definition and Requirements

ref

Reference

A reference to a resource, such as a document, collection, database, etc.

Returns

A new Set Reference for the set which contains the single ref.

Examples

The following query creates a single-item set from the provided ref:

client.query(
  q.Singleton(q.Ref(q.Collection('posts'), '233286601218720256'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Singleton(Ref(Collection("posts"), "233286601218720256"))
result = client.query(
  q.singleton(q.ref(q.collection("posts"), "233286601218720256"))
)
print(result)
SetRef({'singleton': Ref(id=233286601218720256, collection=Ref(id=posts, collection=Ref(id=collections)))})
result, err := client.Query(
	f.Singleton(f.Ref(f.Collection("posts"), "233555580689580553")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
{map[singleton:{233555580689580553 0xc00009b410 0xc00009b410 <nil>}]}
try
{
    Value result = await client.Query(
        Singleton(Ref(Collection("posts"), "233286601218720256"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
SetRefV(System.Collections.Generic.Dictionary`2[System.String,FaunaDB.Types.Value])
Singleton(Ref(Collection('posts'), '233286601218720256'))
Singleton(Ref(Collection("posts"), "233286601218720256"))
Query metrics:
  •    bytesIn:  70

  •   bytesOut: 152

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 9ms

  •    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!