Create a child database

Reading or writing database documents requires an admin key.

Problem

You need to create a child database.

Solution

Use the CreateDatabase function:

try
{
    Value result = await client.Query(
        CreateDatabase(Obj("name", "annuvin"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "annuvin", collection = RefV(id = "databases")),ts: LongV(1622573448030000),name: StringV(annuvin),global_id: StringV(yoijia8e1ybyy))
result, err := adminClient.Query(
	f.CreateDatabase(f.Obj{"name": "annuvin"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[global_id:yoiji3uwcybyy name:annuvin ref:{annuvin 0xc0001804b0 0xc0001804b0 <nil>} ts:1622573470750000]
System.out.println(
        adminClient.query(
            CreateDatabase(Obj("name", Value("annuvin")))
        ).get());
{ref: ref(id = "annuvin", collection = ref(id = "databases")), ts: 1622573481000000, name: "annuvin", global_id: "yoiji48irybyy"}
adminClient.query(
  q.CreateDatabase({ name: 'annuvin' })
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Database("annuvin"),
  ts: 1622573508720000,
  name: 'annuvin',
  global_id: 'yoiji573cydyy'
}
result = adminClient.query(
  q.create_database({"name": "annuvin"})
)
print(result)
{'ref': Ref(id=annuvin, collection=Ref(id=databases)), 'ts': 1622573511610000, 'name': 'annuvin', 'global_id': 'yoijihdqgydyy'}
try {
  println(Await.result(
    client.query(
        CreateDatabase(Obj("name" -> "annuvin"))
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{ref: ref(id = "annuvin", collection = ref(id = "databases")), ts: 1622573538010000, name: "annuvin", global_id: "yoiji7zyoybyy"}
CreateDatabase({ name: 'annuvin' })
{
  ref: Database("annuvin"),
  ts: 1624310575420000,
  name: 'annuvin',
  global_id: 'yoat8nnggybyy'
}

Discussion

It is not possible to create parent or peer databases with the CreateDatabase function; you can only create a child database in the current database.

More information

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!