collection.createData()
Create a document in the collection with a data field.
Description
Creates a document in the collection with the provided properties fields and values.
If the following fields are included, they populate the document .data field: id, ts, ttl, and data. Otherwise, the data field isn’t instantiated.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
properties |
Yes |
Fields to populate the document, including the data field. |
properties that populate the .data field
Name | Type | Required | Description |
---|---|---|---|
ttl |
Timestamp indicating when to remove the document.
When the document is removed, it ceases to exist. |
||
id |
User-defined document |
||
data |
The key:value pairs to populate the data field. |
Examples
Create a document with the id
and coll
metadata fields:
Customer.createData({
id: 12345,
coll: "Person",
name: "John Doe",
email: "john.doe@example.com",
address: {
street: "123 Main St",
city: "San Francisco",
state: "CA",
postalCode: "12345",
country: "United States"
}
})
{
id: "412999820218728960",
coll: Customer,
ts: Time("2099-07-30T22:04:39.400Z"),
cart: null,
orders: "hdW...",
name: "John Doe",
email: "john.doe@example.com",
address: {
street: "123 Main St",
city: "San Francisco",
state: "CA",
postalCode: "12345",
country: "United States"
},
data: {
coll: "Person",
id: 12345
}
}
createData()
treats any metadata field as a document field and nests it in the
document’s data
property.
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!