[SOLVED] always getting `Document with the requested ID already exists.' in cloud function
- 0
- Databases
- Functions
const {
clinicRef,
patientRef,
orgRef,
type,
startDate,
endTime,
endDate,
startTime,
}: CreateConsultationData = req.body;
const databases = new Databases(client);
const teams = new Teams(client);
const functions = new Functions(client);
const { "x-appwrite-user-id": userId, "user-id": backUp }: RequestHeaders =
req.headers;
const creator = userId || backUp;
if (!creator) {
return res.send(
JSON.stringify({
message: "either x-appwrite-user-id or user-id header is required",
}),
404,
{
"content-type": "application/json",
}
);
}
try {
const response = await databases.createDocument(
Bun.env.DATABASE_ID,
Bun.env.CONSULTATION_COLLECTION_ID,
ID.unique(),
{
orgRef,
patientRef,
patient: patientRef,
clinicRef,
facility: clinicRef,
type,
startDate,
endDate,
startTime,
endTime,
}
);
return res.send(
JSON.stringify({
message: "Consultation created",
data: response,
}),
200,
{
"content-type": "application/json",
}
);
} catch (e) {
error(`Error creating facility: ${e.message}`);
return res.send(
JSON.stringify({
message: `Error creating facility: ${e.message}`,
}),
500,
{
"content-type": "application/json",
}
);
}
When I have to delete the existing document, this code above it will executed successfully, after the execution, now I am getting back the error of Document with the reuqested ID already exists
Do you have a unique index on the collection or any related collections?
Is there relationships? That might be a problem too
I dont have unique index
I will check the relationship
It could be trying to create a related document that already exists..what's your payload?
It seems the relationship
is my relation correct?
Facility can only be linked to 1 consultation?
many consultation
ohh I see one to many should be
Uhh many to one
ok I will try
thanks steven its now working
[SOLVED] always getting `Document with the requested ID already exists.' in cloud function
Recommended threads
- My cloud functions failing 3 days ago (P...
Hi, My cloud function using python has been failing for 3 days, I didn't push any new deployments... Its something to do with it not recognising the entrypoi...
- Scheduled works locking the entire Maria...
I have a scheduled function and apparently that or something is locking the entire MariaDB database and Appwrite is giving MariaDB errors. This error persists e...
- Python Function not working
I am getting this issue as well. Doesnt look like there was a solution as you guys were not able to replicate. Below is my code as well as the error. I started...