Back

Updating a document is throwing a 409 conflict: "Document with the requested ID already exists."

  • 0
  • Self Hosted
  • Databases
  • Web
  • REST API
deep-printerverse
29 Feb, 2024, 08:13

Hello, I was trying to update a document with some data, but I keep getting this exception.

TypeScript
AppwriteException: Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.

Here is how the request looks like:

TypeScript
Request URL:
https://[url]/v1/databases/654203868c7fe15422da/collections/65c3c0105759db977ea3/documents/65c3c265cdef124f221a
Request Method:
PATCH
Status Code:
409 Conflict

Updating other documents is fine and has not caused me any issues. I must be doing something wrong, but I do not know what. I do not think the error message makes sense. Any help would be greatly appreciated.

TL;DR
Developers are receiving a "Document with the requested ID already exists" error when trying to update a specific document. The issue pertains specifically to the `employee_editable` field. The solution involves ensuring unique document IDs are used when updating documents, potentially by using `ID.unique()`.
darShan
29 Feb, 2024, 08:19

could you show the implementation?

deep-printerverse
29 Feb, 2024, 08:26

Sue, this is the document I was trying to update

TypeScript
{
    "name": "Personal Information",
    "employee_editable": true,
    "enabled": true,
    "for": "6542042f42dfcbf0f594",
    "$id": "65c3c265cdef124f221a",
    "$collectionId": "65c3c0105759db977ea3",
    "$databaseId": "654203868c7fe15422da",
    "$createdAt": "2024-02-07T17:48:21.843+00:00",
    "$updatedAt": "2024-02-08T07:19:10.082+00:00",
    "$permissions": [],
    "form_fields": [{...}]
}

Note that form_fields is a relationship to another collection. I was trying to update the employee_editable field using

TypeScript
 await databases.updateDocument(databaseID!, collectionID!, formDocumentID, {
     employee_editable: formProperties.employeeEditable
  });

which made a request I sent in the original message

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more