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: "340888671260508194",
  coll: Product;
  ts: 1661355620630000,
  name: "Hard Anodised 12 Kadhai",
  type: "Kitchen & Dining",
  price: 999,
  quantity: 30,
  data: {
    "id":   "Premium Kadhai"
  }
}

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 word. By creating and using an alias, the resource doesn’t have to be renamed. See the application to System-level reserved Collection names.

This example shows how to use a schema alias to rename a Collection:

Collection.byName("my-legacy-collection")!.update({
  alias: "MyColl"
})

 

Using the alias keyword to define an alias name allows you to refer to the aliased entity using the alias name in subsequent requests:

MyColl.firstWhere(.letter < "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.

See also

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!