References are their own special data type. References are not Documents and cannot have user defined data attached to them.
Every Ref has id
and collection
fields. Note that references to schema are also Refs, so you can also Select
the id
and collection
for Schema Refs as well.
Here is an example:
Map(
[
Ref(Collection("users"), "319254125213646912"), // Document Ref
Collection("users"), // user Schema Ref
Collections() // native Schema Ref
Function("Test"), // user Schema Ref
Functions() // native Schema Ref
],
ref => ({
id: Select("id", ref),
collection: Select("collection", ref, null)
})
)
Here is the result as formatted FQL
[
{ id: "319254125213646912", collection: Collection("users") },
{ id: "users", collection: Collections() },
{ id: "collections", collection: Collections() },
{ id: "users", collection: Collections() },
{ id: "collections", collection: Collections() },
{ id: "Test", collection: Functions() },
{ id: "collections", collection: Collections() },
]
Here’s the raw output for comparison. I like to share this, because it shows the recursive nature of the Refs.
Note that the over-the-wire protocol is an implementation detail and subject to change. The drivers abstract this away, for example providing getters for id
and collection
on Refs. Do NOT rely on manipulating the raw output for production purposes.
[
{
"@ref": {
"id": "319254125213646912",
"collection": {
"@ref": {
"id": "users",
"collection": {
"@ref": {
"id": "collections"
}
}
}
}
}
},
{
"@ref": {
"id": "users",
"collection": {
"@ref": {
"id": "collections"
}
}
}
},
{
"@ref": {
"id": "collections",
"collection": {
"@ref": {
"id": "collections"
}
}
}
},
{
"@ref": {
"id": "tester",
"collection": {
"@ref": {
"id": "functions"
}
}
}
},
{
"@ref": {
"id": "functions",
"collection": {
"@ref": {
"id": "collections"
}
}
}
}
]