import { Client, Databases, ID } from "appwrite";
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const databases = new Databases(client);
const id = Date.now(); //this does not work, error recieved is shown after code ends
const promise = databases.createDocument(
'[DATABASE_ID]',
'[COLLECTION_ID]',
id,
data
);
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
error: AppwriteException: Invalid documentId
param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char
But the same method works in upload file:
import { Client, Storage } from "appwrite";
const client = new Client();
const storage = new Storage(client);
client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
;
const id = Date.now() //this works and file is created
const promise = storage.createFile('[BUCKET_ID]', id, document.getElementById('uploader').files[0]);
promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
Cannot create documents using custom id in web (works if in console)
Date.now() returns an int, and the document ID needs to be a string. so you can do something like const id = Date.now().toString()
You can review the docs here to see the properties and their type expectancies here: https://appwrite.io/docs/references/cloud/models/document
Recommended threads
- Seed db
hello there... is this correct way to seed appwrite
- Cant configure email templates
i configure it on the console, and when i send the OTP, it sends with appwrite's email (instead of custom smtp) and with the branding, but i have the Pro (educa...
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...