CreateCollection( param_object )
CreateCollection( param_object )
CreateCollection( param_object )
CreateCollection( param_object )
create_collection( param_object )
CreateCollection( param_object )


The CreateCollection function is used to create a collection that groups documents. Once the collection has been created, it is possible to create documents within the collection. You cannot create a collection and insert documents into that collection in the same transaction.

Unique name required

The collection name must be unique within the database. If you try to lookup a collection by name and only create it if it does not exist, the operation might fail if another transaction has created the collection 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 the collection. Collections cannot be named any of the following reserved words: events, set, self, documents, or _.


Optional - This is user-defined metadata for the collection. It is provided for the developer to store information at the collection level.


Optional - The number of days that document history is retained for in this collection. The default is 30 days.

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


Optional - The number of days documents are retained for this collection. Documents 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 collection level. See collection permissions for additional details.


An object containing the fields returned by the CreateCollection function is described below.

Field Name Field Type Definition and Requirements


The reference is an automatically generated identifier within the database to uniquely identify the collection that was created.


The name of the collection that was created.


The timestamp, with microsecond resolution, associated with the creation of the collection.


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


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

    CreateCollection(Obj("name", "boons"))
ObjectV(ref: RefV(id = "boons", collection = RefV(id = "collections")),ts: LongV(1603756173470000),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 0xc00009a0f0 0xc00009a0f0 <nil>} ts:1603747133670000]
        CreateCollection(Obj("name", Value("boons")))
  ref: ref(id = "boons", collection = ref(id = "collections")),
  ts: 1526674566802938,
  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: 1592054207270000,
  history_days: 30,
  name: 'boons'
result = client.query(
    q.create_collection({"name": "boons"})
{'ref': Ref(id=boons, collection=Ref(id=collections)), 'ts': 1592850281880000, 'history_days': 30, 'name': 'boons'}
client.query(CreateCollection(Obj("name" -> "boons")))
{ref: ref(id = "boons", collection = ref(id = "collections")), ts: 1594484979620000, history_days: 30, name: "boons"}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email

Thank you for your feedback!