Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/routes/docs/products/databases/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
label: 'CSV imports',
href: '/docs/products/databases/csv-imports',
new: isNewUntil('31 Jul 2025')
},
{
label: 'Timestamp overrides',
href: '/docs/products/databases/timestamp-overrides'
}
]
},
Expand Down
290 changes: 20 additions & 270 deletions src/routes/docs/products/databases/legacy/documents/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -375,273 +375,7 @@ mutation {
```
{% /multicode %}

# Set custom $createdAt and $updatedAt {% #custom-timestamps %}
{% info title="Server SDKs required" %}
To manually set `$createdAt` and `$updatedAt`, you must use a **server SDK** with an **API key**. These attributes can be passed inside the `data` parameter on any of the create, update, or upsert routes (single or bulk).
{% /info %}

You can override a document's timestamps by providing ISO 8601 strings (for example, `2025-08-10T12:34:56.000Z`) in the `data` payload. If these attributes are not provided, Appwrite will set them automatically.

{% multicode %}
```server-nodejs
const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>')
.setKey('<API_KEY>');

const databases = new sdk.Databases(client);

// Single document (create)
await databases.createDocument(
'<DATABASE_ID>',
'<COLLECTION_ID>',
sdk.ID.unique(),
{
'$createdAt': new Date('2025-08-10T12:34:56.000Z').toISOString(),
'$updatedAt': new Date('2025-08-10T12:34:56.000Z').toISOString(),
// ...your attributes
}
);

// Single document (update)
await databases.updateDocument(
'<DATABASE_ID>',
'<COLLECTION_ID>',
'<DOCUMENT_ID>',
{
'$updatedAt': new Date('2025-08-10T12:34:56.000Z').toISOString(),
// ...your attributes
}
);

// Bulk (create)
await databases.createDocuments(
'<DATABASE_ID>',
'<COLLECTION_ID>',
[
{
'$id': sdk.ID.unique(),
'$createdAt': new Date('<CUSTOM_DATE>').toISOString(),
'$updatedAt': new Date('<CUSTOM_DATE>').toISOString(),
// ...your attributes
}
]
);

// Bulk (upsert)
await databases.upsertDocuments(
'<DATABASE_ID>',
'<COLLECTION_ID>',
[
{
'$id': '<DOCUMENT_ID_OR_NEW_ID>',
'$createdAt': new Date('<CUSTOM_DATE>').toISOString(),
'$updatedAt': new Date('<CUSTOM_DATE>').toISOString(),
// ...your attributes
}
]
);
```
```server-php
use Appwrite\Client;
use Appwrite\ID;
use Appwrite\Services\Databases;

$client = (new Client())
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
->setProject('<YOUR_PROJECT_ID>') // Your project ID
->setKey('<YOUR_API_KEY>'); // Your secret API key

$databases = new Databases($client);

// Single document (create)
$databases->createDocument(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documentId: '<DOCUMENT_ID>',
[
'$createdAt' => (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
'$updatedAt' => (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
// ...your attributes
]
);

// Single document (update)
$databases->updateDocument(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documentId: '<DOCUMENT_ID>',
[
'$updatedAt': (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
// ...your attributes
]
);

// Bulk (create)
$databases->createDocuments(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
[
[
'$id': ID::unique(),
'$createdAt': (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
'$updatedAt': (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
// ...your attributes
]
]
);

// Bulk (upsert)
$databases->upsertDocuments(
databaseId: '<DATABASE_ID>',
collectionId: '<COLLECTION_ID>',
documents: [
[
'$id' => '<DOCUMENT_ID_OR_NEW_ID>',
'$createdAt' => (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
'$updatedAt' => (new DateTime('<CUSTOM_DATE>'))->format(DATE_ATOM),
// ...your attributes
],
],
);
```
```server-swift
import Appwrite
import Foundation

// MARK: - Client setup
let client = Client()
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
.setProject("<YOUR_PROJECT_ID>") // Your project ID
.setKey("<YOUR_API_KEY>") // Your secret API key

let databases = Databases(client)

let isoFormatter = ISO8601DateFormatter()
isoFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let customDate = isoFormatter.date(from: "<CUSTOM_DATE>") ?? Date()
let createdAt = isoFormatter.string(from: customDate)
let updatedAt = isoFormatter.string(from: customDate)

// MARK: - Single document (create)
do {
let created = try await databases.createDocument(
databaseId: "<DATABASE_ID>",
collectionId: "<COLLECTION_ID>",
documentId: "<DOCUMENT_ID>",
data: [
"$createdAt": createdAt,
"$updatedAt": updatedAt,
// ...your attributes
]
)
print("Created:", created)
} catch {
print("Create error:", error)
}

// MARK: - Single document (update)
do {
let updated = try await databases.updateDocument(
databaseId: "<DATABASE_ID>",
collectionId: "<COLLECTION_ID>",
documentId: "<DOCUMENT_ID>",
data: [
"$updatedAt": updatedAt,
// ...your attributes
]
)
print("Updated:", updated)
} catch {
print("Update error:", error)
}

// MARK: - Bulk (create)
do {
let bulkCreated = try await databases.createDocuments(
databaseId: "<DATABASE_ID>",
collectionId: "<COLLECTION_ID>",
documents: [
[
"$id": ID.unique(),
"$createdAt": createdAt,
"$updatedAt": updatedAt,
// ...your attributes
]
]
)
print("Bulk create:", bulkCreated)
} catch {
print("Bulk create error:", error)
}

// MARK: - Bulk (upsert)
do {
let bulkUpserted = try await databases.upsertDocuments(
databaseId: "<DATABASE_ID>",
collectionId: "<COLLECTION_ID>",
documents: [
[
"$id": "<DOCUMENT_ID_OR_NEW_ID>",
"$createdAt": createdAt,
"$updatedAt": updatedAt,
// ...your attributes
]
]
)
print("Bulk upsert:", bulkUpserted)
} catch {
print("Bulk upsert error:", error)
}
```
```server-python
from appwrite.client import Client
from appwrite.services.databases import Databases
from appwrite.id import ID
from datetime import datetime, timezone

client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
client.set_project('<PROJECT_ID>')
client.set_key('<API_KEY>')

databases = Databases(client)

iso = datetime(2025, 8, 10, 12, 34, 56, tzinfo=timezone.utc).isoformat()

# Single (create)
databases.create_document(
database_id='<DATABASE_ID>',
collection_id='<COLLECTION_ID>',
document_id=ID.unique(),
data={
'$createdAt': iso,
'$updatedAt': iso,
# ...your attributes
}
)

# Bulk (create)
databases.create_documents(
database_id='<DATABASE_ID>',
collection_id='<COLLECTION_ID>',
documents=[{
'$id': ID.unique(),
'$createdAt': iso,
'$updatedAt': iso,
# ...your attributes
}]
)
```
{% /multicode %}

{% info title="Timestamp format and usage" %}
- Values must be valid ISO 8601 date-time strings (UTC recommended). Using `toISOString()` (JavaScript) or `datetime.isoformat()` (Python) is a good default.
- You can set either or both attributes as needed. If omitted, Appwrite sets them.
- This also works with bulk routes such as `createDocuments` and `upsertDocuments`. See [Bulk operations](#bulk-operations).
{% /info %}

# Permissions {% #permissions %}
In Appwrite, permissions can be granted at the collection level and the document level.
Expand All @@ -652,10 +386,26 @@ Users only need to be granted access at either the collection or document level

[Learn about configuring permissions](/docs/products/databases/legacy/permissions).

# Bulk operations {% #bulk-operations %}
# Next steps {% #next-steps %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add this to the new Rows page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a next steps section in the rows docs


Continue learning with these related guides:

{% cards %}
{% cards_item href="/docs/products/databases/queries" title="Queries" %}
Learn how to filter, sort, and search your documents with various query operators.
{% /cards_item %}

{% cards_item href="/docs/products/databases/pagination" title="Pagination" %}
Handle large datasets by implementing pagination in your document queries.
{% /cards_item %}

In Appwrite, you can perform bulk operations on documents within a collection. This allows you to create, update, upsert, or delete multiple documents in a single request.
{% cards_item href="/docs/products/databases/bulk-operations" title="Bulk operations" %}
Perform create, update, and delete operations on multiple documents simultaneously.
{% /cards_item %}

As of now, bulk operations can only be performed via the server-side SDKs. The client-side SDKs do not support bulk operations.
{% cards_item href="/docs/products/databases/timestamp-overrides" title="Timestamp overrides" %}
Set custom creation and update timestamps when migrating data or backdating records.
{% /cards_item %}
{% /cards %}

[Learn more about bulk operations](/docs/products/databases/legacy/bulk-operations).
[Learn more about bulk operations](/docs/products/databases/bulk-operations).
Loading