Rename a collection

Problem

You need to rename a collection within the current database.

Solution

Use the Update function:

try
{
    Value result = await client.Query(
        Update(
            Collection("dilapidated_huts"),
            Obj("data", Obj("env", "test"))
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "dilapidated_huts", collection = RefV(id = "collections")),ts: LongV(1635183024850000),history_days: LongV(30),name: StringV(dilapidated_huts),data: ObjectV(env: StringV(test)))
result, err := adminClient.Query(
	f.Update(
		f.Collection("dilapidated_huts"),
		f.Obj{"data": f.Obj{"env": "test"}},
	))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[env:test] history_days:30 name:dilapidated_huts ref:{dilapidated_huts 0xc0001804b0 0xc0001804b0 <nil>} ts:1635183036860000]
System.out.println(
        adminClient.query(
            Update(
                Collection(Value("dilapidated_huts")),
                Obj("data", Obj("env", Value("test")))
            )
        ).get());
{ref: ref(id = "dilapidated_huts", collection = ref(id = "collections")), ts: 1635183075770000, history_days: 30, name: "dilapidated_huts", data: {env: "test"}}
adminClient.query(
  q.Update(
    q.Collection('dilapidated_huts'),
    { data: { env: 'test' } }
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Collection("dilapidated_huts"),
  ts: 1635183086600000,
  history_days: 30,
  name: 'dilapidated_huts',
  data: { env: 'test' }
}
result = adminClient.query(
  q.update(
    q.collection("dilapidated_huts"),
    {"data": {"env": "test"}}
  )
)
print(result)
{'ref': Ref(id=dilapidated_huts, collection=Ref(id=collections)), 'ts': 1635183090850000, 'history_days': 30, 'name': 'dilapidated_huts', 'data': {'env': 'test'}}
try {
  println(Await.result(
    client.query(
      Update(
        Collection("dilapidated_huts"),
        Obj("data" -> Obj("env" -> "test"))
      )
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{name: "dilapidated_huts", data: {env: "test"}, ts: 1635183223290000, ref: ref(id = "dilapidated_huts", collection = ref(id = "collections")), history_days: 30}
Update(
  Collection('dilapidated_huts'),
  { data: { env: 'test' } }
)
{
  ref: Collection("dilapidated_huts"),
  ts: 1635183253930000,
  history_days: 30,
  name: 'dilapidated_huts',
  data: { env: 'test' }
}
Query metrics:
  •    bytesIn:   99

  •   bytesOut:  186

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  227

  • writeBytes:  113

  •  queryTime: 18ms

  •    retries:    0

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!