[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
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...
- Inquiry: How to Reduce Cold Start Durati...
Hey! I was using Python for the function runtime, but after reading that Go has the fastest runtime, I switched my code over to Go. However, I'm still seeing co...