Collection.create()
Learn: Collection schema |
---|
We recommend you use FSL to create and update user-defined collections. See Collection schema. |
Create a collection.
Description
The Collection.create()
method creates a collection definition
document with the provided data, which must include a unique
collection name.
Collection.create({ name: "Inventory" })
You can’t create a collection and use it in the same query. Use separate queries instead.
Avoid concurrent schema changes
Collection.create()
creates a
collection schema.
Concurrent schema writes in the same database can cause contended transactions, even if the changes affect different schemas. This includes schema changes made using:
-
The Fauna Dashboard.
-
The Fauna CLI's
schema push
command. -
FQL methods, such as
Collection.create()
orrole.update()
, that write to a schema’s underlying document.
A schema change triggers a transaction that validates all schemas for the database. To avoid errors, perform schema changes sequentially instead.
Parameters
Examples
Create a collection named Inventory
without defining fields for the
collection:
Collection.create({ name: "Inventory" })
{
name: "Inventory",
coll: Collection,
ts: Time("2099-02-18T20:49:36.680Z"),
indexes: {},
constraints: []
}
Fields can be added and changed with the
document.update()
and
document.replace()
methods.
See also
Collection document definition to delete a collection.
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!