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.

Database metadata

Reading or writing database documents requires an admin key.

Problem

You want to store additional metadata within a database document.

Solution

Set the data field in a database:

adminClient.query(
  q.Update(q.Database('llyr'), { data: { env: 'test' } })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Database("llyr"),
  ts: 1622573509680000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoiji573cydyy'
}
result = adminClient.query(
  q.update(q.database("llyr"), {"data": {"env": "test"}})
)
print(result)
{'ref': Ref(id=llyr, collection=Ref(id=databases)), 'ts': 1622573512400000, 'name': 'llyr', 'data': {'env': 'test'}, 'global_id': 'yoijihdqgydyy'}
result, err := adminClient.Query(
	f.Update(
		f.Database("llyr"),
		f.Obj{"data": f.Obj{"env": "test"}},
	))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[env:test] global_id:yoiji3uwcybyy name:llyr ref:{llyr 0xc00011da10 0xc00011da10 <nil>} ts:1622573473320000]
try
{
    Value result = await client.Query(
        Update(Database("llyr"), Obj("data", Obj("env", "test")))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "llyr", collection = RefV(id = "databases")),ts: LongV(1622573463870000),name: StringV(llyr),data: ObjectV(env: StringV(test)),global_id: StringV(yoijia8e1ybyy))
System.out.println(
        adminClient.query(
            Update(
                Database(Value("llyr")),
                Obj("data", Obj("env", Value("test")))
            )
        ).get());
{ref: ref(id = "llyr", collection = ref(id = "databases")), ts: 1622573501510000, name: "llyr", data: {env: "test"}, global_id: "yoiji48irybyy"}
Update(Database('llyr'), { data: { env: 'test' } })
{
  ref: Database("llyr"),
  ts: 1624310577730000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoat8nnggybyy'
}
Query metrics:
  •    bytesIn:   85

  •   bytesOut:  170

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  243

  • writeBytes:  243

  •  queryTime: 17ms

  •    retries:    0

Discussion

It is not possible to revise the parent database, the current database, or any of the current database’s peers using Update. You can only add metadata to the documents that describe child databases.

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!