Rename a child database

Reading or writing database documents requires an admin key.

Problem

You need to change the name of a child database.

Solution

Use the Update function:

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

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

Discussion

It is not possible to rename the parent database, the current database, or any of the current database’s peers (that may exist) using Update. You can only rename a child databases.

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!