CreateCollection
CreateCollection( param_object )
CreateCollection( param_object )
CreateCollection( param_object )
CreateCollection( param_object )
create_collection( param_object )
CreateCollection( param_object )
Description
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.
Temporality
You can control how long each document in a collection retains its version
history with the history_days
parameter. By default, collections retain
all versions of a document for 30 days. Document history contributes to
consumed storage. Indexes retain
the history of indexed fields, which can reduce the performance of indexes
as the history accumulates.
Setting Setting |
To learn more about document version history, see Temporality.
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
The |
param_object
Field Name | Field Type | Definition and Requirements | ||
---|---|---|---|---|
|
The name of the collection. Cannot be |
|||
|
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 |
|||
|
Optional - A timestamp indicating the document’s time-to-live, which is when the document should be removed. When a document is removed, the document’s existence ceases (as if it never existed); temporal queries cannot recover the document.
|
|||
|
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
|
|||
|
Optional - Provides the ability to enable permissions at the collection level. See collection permissions for additional details. |
Returns
An Object containing the fields returned by the CreateCollection
function:
Field Name | Field Type | Definition and Requirements |
---|---|---|
|
A Reference to 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. |
Examples
The following query creates a collection called "boons" with defaults:
ObjectV(ref: RefV(id = "boons", collection = RefV(id = "collections")),ts: LongV(1603756173470000),history_days: LongV(30),name: StringV(boons))
map[history_days:30 name:boons ref:{boons 0xc00009a0f0 0xc00009a0f0 <nil>} ts:1603747133670000]
{
ref: ref(id = "boons", collection = ref(id = "collections")),
ts: 1526674566802938,
history_days: 30,
name: "boons"
}
{
ref: Collection("boons"),
ts: 1592054207270000,
history_days: 30,
name: 'boons'
}
{'ref': Ref(id=boons, collection=Ref(id=collections)), 'ts': 1592850281880000, 'history_days': 30, 'name': 'boons'}
{
ref: Collection("boons"),
ts: 1624310355980000,
history_days: 30,
name: 'boons'
}
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!