[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
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Function in Node.JS to monitor events ar...
Hello everyone. I'm creating my first Node.JS function, but I don't have much experience with node and javascript. I'm trying to create a function, that monito...