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:

curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{ "database": "prydain" }'
client.Query(Database("prydain"));
System.out.println(client.query(Database(Value("prydain"))).get());
result, _ := client.Query(f.Database("prydain"))

fmt.Println(result)
client.query(Database("prydain"))
client.query(q.database("prydain"))
client.query(q.Database('prydain'))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{ "resource": { "@ref": "databases/prydain" } }
{ "@ref": "databases/prydain" }
ref(id = "prydain", collection = ref(id = "databases"))
{prydain 0xc420316a60 <nil>}
{ "@ref": "databases/prydain" }
{ "@ref": "databases/prydain" }
Ref(id=prydain, collection=Ref(id=databases))

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!