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


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

A Class was renamed to a Collection in Fauna 2.7.0. This function 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 the class has been created, it is possible to create instances 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 within 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.


Argument Type Definition and Requirements


The param_object fields are described below.


Field Name Field Type Definition and Requirements


The name of a class (now collection).

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


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.


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

Setting history_days to null retains this class' (now, collection’s) history forever. Setting history_days to 0 retains only the current version of each document in this class (now, collection); no history is retained.


Optional - The number of days documents are retained for this class. Instances which have not been updated within the configured TTL duration are removed. Setting ttl_days to null retains documents forever. The default is null.

Removal is handled by a background task, so once a document (including collections, databases, indexes, keys, roles, and tokens) "expires" due to the setting in the ttl_days field, it could be some time (hours or days) before the removal occurs. There is no guarantee that removal actually occurs.

For more immediate removal, use the ttl field on documents that should have limited lifespans. See Documents for details.


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


An Object containing the fields returned by the CreateClass function:

Field Name Field Type Definition and Requirements


A Reference to the class that was created.


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


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


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


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

    Value result = await client.Query(
        CreateCollection(Obj("name", "boons"))
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))
result, err := client.Query(
	f.CreateCollection(f.Obj{"name": "boons"}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
map[history_days:30 name:boons ref:{boons 0xc0001780c0 0xc0001780c0 <nil>} ts:1603747131750000]
        CreateCollection(Obj("name", Value("boons")))
{ref: ref(id = "boons", collection = ref(id = "collections")), ts: 1593220411910000, history_days: 30, name: "boons"}
  q.CreateCollection({ name: 'boons' })
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
  ref: Collection("boons"),
  ts: 1592053895890000,
  history_days: 30,
  name: 'boons'
result = client.query(
    q.create_collection({"name": "boons"})
{'ref': Ref(id=boons, collection=Ref(id=collections)), 'ts': 1592845981190000, 'history_days': 30, 'name': 'boons'}
try {
    client.query(CreateCollection(Obj("name" -> "boons"))),
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
{ref: ref(id = "boons", collection = ref(id = "collections")), ts: 1594484955870000, 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

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email

Thank you for your feedback!