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.

Retrieve a single collection

Problem

You need to retrieve a the document that describes a collection from the current database.

Solution

Use the Get function:

client.query(
  q.Get(q.Collection('huts'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Collection("huts"),
  ts: 1622573894320000,
  history_days: 30,
  name: 'huts'
}
result = client.query(
  q.get(q.collection("huts"))
)
print(result)
{'ref': Ref(id=huts, collection=Ref(id=collections)), 'ts': 1622573899290000, 'history_days': 30, 'name': 'huts'}
result, err := client.Query(
	f.Get(f.Collection("huts")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[history_days:30 name:huts ref:{huts 0xc000109830 0xc000109830 <nil>} ts:1622573814740000]
try
{
    Value result = await client.Query(
        Get(Collection("huts"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "huts", collection = RefV(id = "collections")),ts: LongV(1622573782400000),history_days: LongV(30),name: StringV(huts))
System.out.println(
    client.query(
        Get(Collection("huts"))
    ).get());
{ref: ref(id = "huts", collection = ref(id = "collections")), ts: 1622573835420000, history_days: 30, name: "huts"}
Get(Collection('huts'))
{
  ref: Collection("huts"),
  ts: 1624310571870000,
  history_days: 30,
  name: 'huts'
}
Query metrics:
  •    bytesIn:   29

  •   bytesOut:  140

  • computeOps:    1

  •    readOps:    1

  •   writeOps:    0

  •  readBytes:   68

  • writeBytes:    0

  •  queryTime: 21ms

  •    retries:    0

Discussion

A collection document describes the container that contains documents; it is not the container itself.

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!