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.

Collection

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

Collection( name, [database] )
collection( name, [database] )
Collection( name )
ScopedCollection( name, database )
Collection( name, [database] )
Collection( name, [database] )

Description

The Collection function returns a valid Reference for the specified collection name, in the specified child database. If a child database is not specified, the returned collection reference belongs to the current database.

When a child database is specified, an admin key must be used to call Collection (server or client keys, or ABAC tokens, cannot be used to access a child database).

Also, Go does not support optional function parameters, nor function overloading. To specify a child database using the Go driver, call the ScopedCollection function instead of Collection.

Parameters

Parameter Type Definition and Requirements

name

String

The name of a collection.

database

Reference

Optional - A Reference to a child database. If not specified, the current database is used.

A Reference to a child database.

Optional - A Reference to a child database. If not specified, the current database is used.

Optional - A Reference to a child database. If not specified, the current database is used.

Optional - A Reference to a child database. If not specified, the current database is used.

Optional - A Reference to a child database. If not specified, the current database is used.

Optional - A Reference to a child database. If not specified, the current database is used.

Returns

A Reference to a collection with the specified name, in the specified child database (or the current database if database is not specified).

Examples

  1. The following query gets a Reference to the collection named "spells" within the current database:

    client.query(
      q.Collection('spells')
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    Collection("spells")
    result = client.query(
        q.collection("spells")
    )
    print(result)
    Ref(id=spells, collection=Ref(id=collections))
    result, err := client.Query(
    	f.Collection("spells"))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {spells 0xc00008e300 0xc00008e300 <nil>}
    try
    {
        Value result = await client.Query(
            Collection("spells")
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "spells", collection = RefV(id = "collections"))
    Collection('spells')
    Collection("spells")
    Query metrics:
    •    bytesIn:  23

    •   bytesOut:  80

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 4ms

    •    retries:   0

  2. The following query gets a Reference to the collection named "spells" within a child database named "child_db":

    client.query(
      q.Collection('spells', q.Database('child_db'))
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    Collection("spells", Database("child_db"))
    result = client.query(
        q.collection("spells", q.database("child_db"))
    )
    print(result)
    Ref(id=spells, collection=Ref(id=collections), database=Ref(id=child_db, collection=Ref(id=databases)))
    result, err := client.Query(
    	f.ScopedCollection("spells", f.Database("child_db")))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {spells 0xc00008f530 0xc00008f530 0xc00008f590}
    try
    {
        Value result = await client.Query(
            Collection("spells", Database("child_db"))
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "spells", collection = RefV(id = "collections"), database = RefV(id = "child_db", collection = RefV(id = "databases")))
    Collection('spells', Database('child_db'))
    Collection("spells", Database("child_db"))
    Query metrics:
    •    bytesIn:   55

    •   bytesOut:  159

    • computeOps:    1

    •    readOps:    0

    •   writeOps:    0

    •  readBytes:  155

    • writeBytes:    0

    •  queryTime: 10ms

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