Naming and aliasing
This section covers guidelines for naming resources.
Resolving document field name collisions
The document metadata id
, coll
, and ts
fields are reserved. If a
document must use a reserved word as a field name, it can be nested in the
document data
field to avoid colliding with a reserved name. In the
following example, the reserved word id
is nested in the data
field to
avoid collision:
{
id: "777",
coll: Product,
ts: Time("2099-06-25T21:16:36.610Z"),
name: "limes",
description: "Conventional, 16 oz bag",
price: 299,
stock: 30,
category: Category("789"),
data: {
id: "limes"
}
}
Global namespace prefix
The FQL
prefix is reserved to disambiguate global Fauna schema entities
and native API names from user-defined entities.
For example, if you define a UDF named log()
, you can access the built-in
log()
method using the FQL
prefix:
FQL.log("hello world")
The FQL
prefix isn’t required if user-defined names don’t conflict with
the global Fauna names.
Schema aliasing
Collections and UDFs accept an alias field that can then be used to reference a resource with a name that conflicts with a reserved schema name. By creating and using an alias, the resource doesn’t have to be renamed.
This example shows how to use a schema alias to rename a Collection:
@alias(myLegacyCollection)
collection "my-legacy-collection" {
}
Using the alias keyword to define an alias name allows you to refer to the aliased entity using the alias name in subsequent requests:
MyLegacyCollection.firstWhere(.name < "Z")
If the original name doesn’t conflict with an existing name, the entity is available using its name or the alias. If the name does conflict, the entity is available only by the alias.
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!