[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
- Quota not resetting
hi, im using appwrite's free tier plani hit my read limts last month and the billing cycle said it would reset on june 4th but that is today, the billing cycle ...
- Request for temporary 3 to 4 hours datab...
Hi Appwrite Team, I hope you are doing well.We are an early-stage startup currently running on Appwrite Cloud. We have unfortunately exhausted our database rea...
- Realtime Error Invalid query: Syntax err...
I was test driving Self-Hosted Appwrite for my use with Swift IOS apps as a backend while back and after successful trials, I started to move to incorporate int...