Document reference
Solution
Use the Select
function:
ObjectV(document: ObjectV(ref: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),ts: LongV(1625505840300000),data: ObjectV(name: StringV(Alice Crypto),email: StringV(alice@site.example.com))),reference: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),reference collection: RefV(id = "users", collection = RefV(id = "collections")),document ID: StringV(1))
map[document:map[data:map[email:alice@site.example.com name:Alice Crypto] ref:{1 0xc0000925a0 0xc0000925a0 <nil>} ts:1625506145900000] document ID:1 reference:{1 0xc000092780 0xc000092780 <nil>} reference collection:{users 0xc000092870 0xc000092870 <nil>}]
{document: {ref: ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections"))), ts: 1625506508690000, data: {name: "Alice Crypto", email: "alice@site.example.com"}}, reference: ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections"))), reference collection: ref(id = "users", collection = ref(id = "collections")), document ID: "1"}
{
document: {
ref: Ref(Collection("users"), "1"),
ts: 1625505428470000,
data: { name: 'Alice Crypto', email: 'alice@site.example.com' }
},
reference: Ref(Collection("users"), "1"),
'reference collection': Collection("users"),
'document ID': '1'
}
{'document': {'ref': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'ts': 1625505236270000, 'data': {'name': 'Alice Crypto', 'email': 'alice@site.example.com'}}, 'reference': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'reference collection': Ref(id=users, collection=Ref(id=collections)), 'document ID': '1'}
{
document: {
ref: Ref(Collection("users"), "1"),
ts: 1625504819720000,
data: { name: 'Alice Crypto', email: 'alice@site.example.com' }
},
reference: Ref(Collection("users"), "1"),
'reference collection': Collection("users"),
'document ID': '1'
}
Discussion
The example uses the Let
function to fetch the document, and then
return an object that reports the document itself, the document’s
reference, and the components of the document reference.
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!