Back

Document with the requested ID already exists.

  • 0
  • Databases
  • Web
sean_hanck
14 Feb, 2023, 06:42

I'm getting an error when trying to create a 2nd document in a collection....

I've made a VueJs ui that allows a user to update a collection of documents, after the first document was created all documents that in that collection throws the error in the title. I am not assigning an id on create and using the unique() approach. Here is the js for my home rolled upsert function:

saveLayer : ( data, layerId ) => { if( layerId == undefined ){ return api.provider().database.createDocument( Server.database, Server.collections.layers, "unique()", data ); } else { return api.provider().database.updateDocument( Server.database, Server.collections.layers, layerId, data ); } }

for the first createDocument everything works as expected, with the document created as expected and then the second document (and 3rd and 4th or how many documents need creating) fails with that error. The payload on the web request sent out looks good as in the attach screen capture. I've deleted the document causing the duplicate from the collection and get the same issue again (but the document id is different).

Any pointers as what I'm doing wrong ?

Thanks

TL;DR
User is getting an error when trying to create a second document in a collection. They are not assigning an id on create and using the unique() approach. The first create works fine, but subsequent creates throw the error. They have already tried deleting the duplicate document from the collection, but the issue persists. They are asking for pointers on what they might be doing wrong. Potential Solution: The user may need to check if they have a unique index on the collection.
Drake
14 Feb, 2023, 06:48

Do you have a unique index on the collection?

sean_hanck
14 Feb, 2023, 15:05

yes, I misunderstood the error message, I thought it was related to the id I was created as opposed to the id I was creating. My bad. Thanks for the help.

Drake
14 Feb, 2023, 15:07

No worries. It is a little misleading

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