Collection metadata

Problem

You need to store additional metadata in a collection document.

Solution

Set the data field in a collection:

try
{
    Value result = await client.Query(
        Update(Database("huts"), 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))
result, err := adminClient.Query(
	f.Update(
		f.Database("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] global_id:yoiji3uwcybyy name:llyr ref:{llyr 0xc00011da10 0xc00011da10 <nil>} ts:1622573473320000]
System.out.println(
        adminClient.query(
            Update(
                Database(Value("huts")),
                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"}
adminClient.query(
  q.Update(q.Database('huts'), { data: { env: 'test' } })
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{
  ref: Database("llyr"),
  ts: 1622573509680000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoiji573cydyy'
}
result = adminClient.query(
  q.update(q.database("huts"), {"data": {"env": "test"}})
)
print(result)
{'ref': Ref(id=llyr, collection=Ref(id=databases)), 'ts': 1622573512400000, 'name': 'llyr', 'data': {'env': 'test'}, 'global_id': 'yoijihdqgydyy'}
try {
  println(Await.result(
    client.query(
        Update(
            Collection("huts"),
            Obj("data" -> Obj("env" -> "test"))
        )
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{global_id: "yoiji7zyoybyy", name: "llyr", data: {env: "test"}, ts: 1622573680510000, ref: ref(id = "llyr", collection = ref(id = "databases"))}
Update(Collection('huts'), { data: { env: 'test' } })
{
  ref: Database("llyr"),
  ts: 1624310577730000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoat8nnggybyy'
}

Discussion

Adding metadata to a collection can be used to store any information that helps to distinguish the collection from other collections.

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!