FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

Rename a collection

Problem

You need to rename a collection within the current database.

Solution

Use the Update function:

client.query(
  q.Update(
    q.Collection('huts'),
    { name: 'dilapidated_huts' },
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Collection("dilapidated_huts"),
  ts: 1622573895370000,
  history_days: 30,
  name: 'dilapidated_huts'
}
result = client.query(
  q.update(
    q.collection("huts"),
    { "name": "dilapidated_huts" }
  )
)
print(result)
{'ref': Ref(id=dilapidated_huts, collection=Ref(id=collections)), 'ts': 1622573900340000, 'history_days': 30, 'name': 'dilapidated_huts'}
result, err := client.Query(
	f.Update(
		f.Collection("huts"),
		f.Obj{"name": "dilapidated_huts"},
	))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[history_days:30 name:dilapidated_huts ref:{dilapidated_huts 0xc000109920 0xc000109920 <nil>} ts:1622573818060000]
try
{
    Value result = await client.Query(
        Update(
            Collection("huts"),
            Obj("name", "dilapidated_huts")
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "dilapidated_huts", collection = RefV(id = "collections")),ts: LongV(1622573797800000),history_days: LongV(30),name: StringV(dilapidated_huts))
System.out.println(
    client.query(
        Update(
            Collection("huts"),
            Obj("name", Value("dilapidated_huts"))
        )
    ).get());
{ref: ref(id = "dilapidated_huts", collection = ref(id = "collections")), ts: 1622573868770000, history_days: 30, name: "dilapidated_huts"}
Update(
  Collection('huts'),
  { name: 'dilapidated_huts' },
)
{
  ref: Collection("dilapidated_huts"),
  ts: 1624310573640000,
  history_days: 30,
  name: 'dilapidated_huts'
}
Query metrics:
  •    bytesIn:   80

  •   bytesOut:  164

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  126

  • writeBytes:  362

  •  queryTime: 20ms

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