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. |
Document reference
Solution
Use the Select
function:
{
document: {
ref: Ref(Collection("users"), "1"),
ts: 1668013992680000,
data: { name: 'Alice Crypto', email: 'alice@site.example.com' }
},
reference: Ref(Collection("users"), "1"),
'reference collection': Collection("users"),
'collection name': 'users',
'document ID': '1'
}
{'document': {'ref': Ref(id=1, collection=Ref(id=users, collection=Ref(id=collections))), 'ts': 1668014292890000, '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)), 'collection name': 'users', 'document ID': '1'}
map[collection name:users document:map[data:map[email:alice@site.example.com name:Alice Crypto] ref:{1 0x1400011dec0 0x1400011dec0 <nil>} ts:1668014775490000] document ID:1 reference:{1 0x140001a80c0 0x140001a80c0 <nil>} reference collection:{users 0x140001a81b0 0x140001a81b0 <nil>}]
ObjectV(document: ObjectV(ref: RefV(id = "1", collection = RefV(id = "users", collection = RefV(id = "collections"))),ts: LongV(1668014161170000),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")),collection name: StringV(users),document ID: StringV(1))
{document: {ref: ref(id = "1", collection = ref(id = "users", collection = ref(id = "collections"))), ts: 1668013980490000, 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")), collection name: "users", document ID: "1"}
{
document: {
ref: Ref(Collection("users"), "1"),
ts: 1668013995250000,
data: { name: 'Alice Crypto', email: 'alice@site.example.com' }
},
reference: Ref(Collection("users"), "1"),
'reference collection': Collection("users"),
'collection name': '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.
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!