Index

Index( name, [database] )
Index( name )
ScopedIndex( name, database )
Index( name, [database] )
Index( name, [database] )
index( name, [database] )
Index( name, [database] )

Description

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

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

Parameters

Parameter Type Definition and Requirements

name

The name of an index.

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.

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

Returns

A reference to an index 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 index named "spells_by_element" in the current database:

    try
    {
        Value result = await client.Query(
            Index("spells_by_element")
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "spells_by_element", collection = RefV(id = "indexes"))
    result, err := client.Query(
    	f.Index("spells_by_element"))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {spells_by_element 0xc00017c090 0xc00017c090 <nil>}
    System.out.println(
        client.query(
            Index("spells_by_element")
        ).get());
    ref(id = "spells_by_element", collection = ref(id = "indexes"))
    client.query(
      q.Index('spells_by_element')
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    Index("spells_by_element")
    result = client.query(
      q.index("spells_by_element")
    )
    print(result)
    Ref(id=spells_by_element, collection=Ref(id=indexes))
    Index('spells_by_element')
    Index("spells_by_element")
    Query metrics:
    •    bytesIn:  29

    •   bytesOut:  87

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 4ms

    •    retries:   0

  2. The following query gets a Reference to the index named "spells_by_element" in a child database named "child_db":

    try
    {
        Value result = await client.Query(
            Index("spells_by_element", Database("child_db"))
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    RefV(id = "spells_by_element", collection = RefV(id = "indexes"), database = RefV(id = "child_db", collection = RefV(id = "databases")))
    result, err := client.Query(
    	f.ScopedIndex("spells_by_element", f.Database("child_db")))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    {spells_by_element 0xc000162180 0xc000162180 0xc0001621e0}
    System.out.println(
        client.query(
            Index("spells_by_element", Database("child_db"))
        ).get());
    ref(id = "spells_by_element", collection = ref(id = "indexes"), database = ref(id = "child_db", collection = ref(id = "databases")))
    client.query(
      q.Index('spells_by_element', 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,
    ))
    Index("spells_by_element", Database("child_db"))
    result = client.query(
      q.index("spells_by_element", q.database("child_db"))
    )
    print(result)
    Ref(id=spells_by_element, collection=Ref(id=indexes), database=Ref(id=child_db, collection=Ref(id=databases)))
    Index('spells_by_element', Database('child_db'))
    Index("spells_by_element", Database("child_db"))
    Query metrics:
    •    bytesIn:  61

    •   bytesOut: 166

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes: 155

    • writeBytes:   0

    •  queryTime: 8ms

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