Back

why it says `Document with the requested ID already exists` when i try to create documents in bulk

  • 0
  • Databases
  • Web
manazo
24 Mar, 2023, 16:47

as the title suggests, I'm trying to create some documents in bulk. it's successfully creating the first two, but after that, it's throwing Document with the requested ID already exists. the attachment shows my code for creating docs. I think it's something that I've done wrong. otherwise, it wouldn't follow this "complete first two only" pattern. but I don't have any idea how to even debug it. I've tried console.log(ID.unique()), but it's only printing "unique" as a string. I can't find any flaw in my code as well. and even if my code has some issues, why it's saying Document with the requested ID already exists. the ID creation part is handled by appwrite with ID.unique(). isn't?

TL;DR
The user is encountering an error message stating "Document with the requested ID already exists" when trying to create documents in bulk using Appwrite. They are curious about the root cause of this error. The error is caused by a unique index on the collection, which is throwing a duplicate document error. The error message is misleading as it mentions duplicate ID instead. The issue was resolved by deleting the unnecessary unique index on the collection. To obtain a unique ID using Appwrite, the user should use `const { ID } = import('appwrite')` and `console.log(ID.unique())` should return the unique ID. Solution: Remove
Binyamin
24 Mar, 2023, 16:54

console.log(ID.unique()) should return unique() with the parentheses

Can you try to change the first row to such

TypeScript
const { ID } = import('appwrite')
Drake
24 Mar, 2023, 18:36

Yes, unique() is a special keyword for the Appwrite server.

Do you have a unique index on your collection?

manazo
24 Mar, 2023, 19:04

you're correct. i had an unnecessary unique index on my collection. and the bug was solved after I deleted the index. but I wonder, what was happening under the hood

Drake
24 Mar, 2023, 19:07

it's a misleading error message. we throw a duplicate document error because of the unique index but the error message says it's a duplicate ID.

manazo
24 Mar, 2023, 19:09

what's this duplicate document error and why does this exists

Drake
24 Mar, 2023, 19:09

because you had a unique index

manazo
24 Mar, 2023, 19:12

no no. what I'm asking is, what issue actually appwrite was facing under the hood? when these duplicate document errors are created? I'm just curious cuz I didn't understand what was happening behind the scene, in my case

Binyamin
24 Mar, 2023, 19:18
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