Database

Database( name, [database] )
Database( name, [database] )
Database( name, [database] )
Database( name, [database] )
database( name, [database] )
Database( name, [database] )

Description

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

The Database function only looks up child databases, so finding a database using this function requires you to use an admin key for the current database (a server or client key cannot be used to access any child database).

Parameters

Argument Type Definition and Requirements

name

The name of a collection.

database

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

Returns

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

Examples

The following query gets a reference to the database named "prydain" within the current database:

client.Query(Database("prydain"));
{ "@ref": "databases/prydain" }
curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "database": "prydain" }'
HTTP/1.1 200 OK
{ "resource": { "@ref": "databases/prydain" } }
result, _ := client.Query(f.Database("prydain"))

fmt.Println(result)
{prydain 0xc420316a60 <nil>}
System.out.println(client.query(Database(Value("prydain"))).get());
ref(id = "prydain", collection = ref(id = "databases"))
client.query(q.Database('prydain'))
.then((ret) => console.log(ret))
Ref(id=prydain, collection=Ref(id=databases))
client.query(q.database("prydain"))
{ "@ref": "databases/prydain" }
client.query(Database("prydain"))
{ "@ref": "databases/prydain" }

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!