Collections

Collections( [database] )
Collections( )
ScopedCollections( database )
Collections( [database] )
Collections( [database] )
collections( [database] )
Collections( [database] )

Description

The Collections function, when executed with Paginate, returns an Array of References for all collections in the specified child database. If a child database is not specified, the returned collection references all belong to the current database.

When a child database is specified, an admin key must be used to call Collections (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 ScopedCollections function instead of Collections.

Parameters

Argument Type Definition and Requirements

database

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.

Returns

A Set Reference for the available collections in the specified child database (or the current database if database is not specified).

Examples

  1. The following query lists the References for any collections (up to the pagination limit) within the current database:

    try
    {
        Value result = await client.Query(
            Paginate(Collections())
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    ObjectV(data: Arr(RefV(id = "Letters", collection = RefV(id = "collections")), RefV(id = "People", collection = RefV(id = "collections")), RefV(id = "characters", collection = RefV(id = "collections")), RefV(id = "customers", collection = RefV(id = "collections")), RefV(id = "decrepit_huts", collection = RefV(id = "collections")), RefV(id = "magical_creatures", collection = RefV(id = "collections")), RefV(id = "orders", collection = RefV(id = "collections")), RefV(id = "posts", collection = RefV(id = "collections")), RefV(id = "products", collection = RefV(id = "collections")), RefV(id = "spellbooks", collection = RefV(id = "collections")), RefV(id = "spells", collection = RefV(id = "collections")), RefV(id = "stores", collection = RefV(id = "collections")), RefV(id = "users", collection = RefV(id = "collections"))))
    result, err := client.Query(
    	f.Paginate(f.Collections()))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    map[data:[{Letters 0xc00013e180 0xc00013e180 <nil>} {People 0xc00013e270 0xc00013e270 <nil>} {characters 0xc00013e360 0xc00013e360 <nil>} {customers 0xc00013e450 0xc00013e450 <nil>} {decrepit_huts 0xc00013e540 0xc00013e540 <nil>} {magical_creatures 0xc00013e630 0xc00013e630 <nil>} {orders 0xc00008e180 0xc00008e180 <nil>} {posts 0xc00008e270 0xc00008e270 <nil>} {products 0xc00008e360 0xc00008e360 <nil>} {spellbooks 0xc00008e450 0xc00008e450 <nil>} {spells 0xc00008e540 0xc00008e540 <nil>} {stores 0xc00008e630 0xc00008e630 <nil>} {users 0xc00008e720 0xc00008e720 <nil>}]]
    System.out.println(
        client.query(
            Paginate(Collections())
        ).get());
    {data: [ref(id = "Letters", collection = ref(id = "collections")), ref(id = "People", collection = ref(id = "collections")), ref(id = "characters", collection = ref(id = "collections")), ref(id = "customers", collection = ref(id = "collections")), ref(id = "decrepit_huts", collection = ref(id = "collections")), ref(id = "magical_creatures", collection = ref(id = "collections")), ref(id = "orders", collection = ref(id = "collections")), ref(id = "posts", collection = ref(id = "collections")), ref(id = "products", collection = ref(id = "collections")), ref(id = "spellbooks", collection = ref(id = "collections")), ref(id = "spells", collection = ref(id = "collections")), ref(id = "stores", collection = ref(id = "collections")), ref(id = "users", collection = ref(id = "collections"))]}
    client.query(
      q.Paginate(q.Collections())
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    {
      data: [
        Collection("Letters"),
        Collection("People"),
        Collection("characters"),
        Collection("customers"),
        Collection("decrepit_huts"),
        Collection("magical_creatures"),
        Collection("orders"),
        Collection("posts"),
        Collection("products"),
        Collection("spellbooks"),
        Collection("spells"),
        Collection("stores"),
        Collection("users")
      ]
    }
    result = client.query(
        q.paginate(q.collections())
    )
    print(result)
    {'data': [Ref(id=Letters, collection=Ref(id=collections)), Ref(id=People, collection=Ref(id=collections)), Ref(id=characters, collection=Ref(id=collections)), Ref(id=customers, collection=Ref(id=collections)), Ref(id=decrepit_huts, collection=Ref(id=collections)), Ref(id=magical_creatures, collection=Ref(id=collections)), Ref(id=orders, collection=Ref(id=collections)), Ref(id=posts, collection=Ref(id=collections)), Ref(id=products, collection=Ref(id=collections)), Ref(id=spellbooks, collection=Ref(id=collections)), Ref(id=spells, collection=Ref(id=collections)), Ref(id=stores, collection=Ref(id=collections)), Ref(id=users, collection=Ref(id=collections))]}
    try {
      println(Await.result(
        client.query(Paginate(Collections())),
        5.seconds
      ))
    } catch {
      case unknown: Throwable => println("Error: " + unknown.getMessage())
    }
    {data: [ref(id = "Letters", collection = ref(id = "collections")), ref(id = "People", collection = ref(id = "collections")), ref(id = "characters", collection = ref(id = "collections")), ref(id = "customers", collection = ref(id = "collections")), ref(id = "decrepit_huts", collection = ref(id = "collections")), ref(id = "magical_creatures", collection = ref(id = "collections")), ref(id = "orders", collection = ref(id = "collections")), ref(id = "posts", collection = ref(id = "collections")), ref(id = "products", collection = ref(id = "collections")), ref(id = "spellbooks", collection = ref(id = "collections")), ref(id = "spells", collection = ref(id = "collections")), ref(id = "stores", collection = ref(id = "collections")), ref(id = "users", collection = ref(id = "collections"))]}
  2. The following query lists the References for any collections (up to the pagination limit) within a child database named "child_db":

    try
    {
        Value result = await client.Query(
            Paginate(Collections(Database("child_db")))
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    ObjectV(data: Arr())
    result, err := client.Query(
    	f.Paginate(f.ScopedCollections(f.Database("child_db"))))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    map[data:[]]
    System.out.println(
        client.query(
            Paginate(Collections(Database("child_db")))
        ).get());
    {data: []}
    client.query(
      q.Paginate(q.Collections(q.Database('child_db')))
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    { data: [] }
    result = client.query(
        q.paginate(q.collections(q.database("child_db")))
    )
    print(result)
    {'data': []}
    try {
      println(Await.result(
        client.query(Paginate(Collections(Database("child_db")))),
        5.seconds
      ))
    } catch {
      case unknown: Throwable => println("Error: " + unknown.getMessage())
    }
    {data: []}

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!