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.

CreateClass

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

CreateClass( param_object )
create_class( param_object )
CreateClass( param_object )
CreateClass( param_object )
CreateClass( param_object )
CreateClass( param_object )

Description

This function is deprecated as of Fauna 2.7.0. Use CreateCollection instead.

Fauna 2.7.0 renamed CreateClass to Collection. CreateClass continues to exist for compatibility with older drivers.

The CreateClass function is used to create a class (now, collection) which groups instance objects (now, documents). Once a class is created, it is possible to create instances (now, documents) in the class. You cannot create a class and insert instances into that class in the same transaction.

Unique name required

The class name must be unique in the database. If you try to lookup a class by name and only create it if it does not exist, the operation might fail if another transaction created the class in the meantime.

Parameters

Parameter Type Definition and Requirements

param_object

Object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

name

String

The name of a class (now collection).

Cannot be events, sets, self, documents, or _. Cannot have the % character.

data

Object

Optional - This is user-defined metadata for the class (now, collection). It is provided for the developer to store information at the class (now, collection) level.

history_days

Integer

Optional - The number of days that instance (now, document) history is retained for in this class (now, collection). The default is zero days.

Setting history_days to null retains this class (now, collection) history indefinitely. Setting history_days to the default value of 0 disables history retention for the class and only the current version of each instance (now, document) in this class (now, collection).

See Temporality for details.

ttl

Timestamp

Optional - A timestamp that indicates the time-to-live for a document, which is when the document is removed from the collection and can’t be queried. The document history can continue to be accessed using the Events function, provided the events are in the history retention interval and the document reference is input to the Events function.

ttl_days

Integer

Optional - The number of days instances (now, documents) are retained for this class. Once an instance (now, document) is older than ttl_days, it is removed. Setting ttl_days to null retains instances (now, documents) indefinitely. The default is null.

permissions

Object

Optional - Provides the ability to enable permissions at the class level. See class permissions for more details.

Returns

An Object with the fields returned by the CreateClass function:

Field Name Field Type Definition and Requirements

ref

Reference

A Reference to the created class.

name

String

The name of the created class (now, collection).

ts

Long

The timestamp, with microsecond resolution, associated with the creation of the class (now, collection).

history_days

Integer

The number of days to retain history. 0 means that no history is retained for instances (now, documents) in this class (now, collection), and only the current version is retained. null means that history is retained indefinitely.

Examples

The following query creates a class called "boons" with defaults:

client.query(
  q.CreateCollection({ name: 'boons' })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Collection("boons"),
  ts: 1592053895890000,
  history_days: 30,
  name: 'boons'
}
result = client.query(
    q.create_collection({"name": "boons"})
)
print(result)
{'ref': Ref(id=boons, collection=Ref(id=collections)), 'ts': 1592845981190000, 'history_days': 30, 'name': 'boons'}
result, err := client.Query(
	f.CreateCollection(f.Obj{"name": "boons"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[history_days:30 name:boons ref:{boons 0xc0001780c0 0xc0001780c0 <nil>} ts:1603747131750000]
try
{
    Value result = await client.Query(
        CreateCollection(Obj("name", "boons"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "boons", collection = RefV(id = "collections")),ts: LongV(1603756168550000),history_days: LongV(30),name: StringV(boons))
System.out.println(
    client.query(
        CreateCollection(Obj("name", Value("boons")))
    ).get());
{ref: ref(id = "boons", collection = ref(id = "collections")), ts: 1593220411910000, history_days: 30, name: "boons"}
CreateCollection({ name: 'boons' })
{
  ref: Collection("boons"),
  ts: 1624449118600000,
  history_days: 30,
  name: 'boons'
}
Query metrics:
  •    bytesIn:   49

  •   bytesOut:  142

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  804

  • writeBytes:  325

  •  queryTime: 49ms

  •    retries:    0

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!