Back

Error in ID.unique()

  • 0
  • Accounts
mitsy0_0
14 Jul, 2023, 02:30

this is what I'm getting in console {"id":"unique()","message":"Document with the requested ID already exists.", "success":false}

this is my code

TypeScript
try:
 id = ID.unique()
 result = databases.create_document('database_id', 'collection_id', id, data = data,)
 return res.json({"success": True, "message": "Data added successfully"})
except Exception as e:
      return res.json({"success": False, "message": str(e), 'id': id})```

I imported
`from appwrite.id import ID`
TL;DR
The user encountered an error with the `ID.unique()` function in their code. They are unsure how it works and couldn't find documentation for it. After some discussion, it was discovered that the error was caused by having multiple unique indexes, including one that was just created. The solution is to remove the unnecessary unique index for ID. However, even after removing it, the error persisted. The user provided their code and the error message they received in the console. No further solution was provided in the thread.
Drake
14 Jul, 2023, 02:32

Do you have a unique index on the collection?

mitsy0_0
14 Jul, 2023, 02:40

I just created

mitsy0_0
14 Jul, 2023, 02:40

Its still giving the same error

Nevus
14 Jul, 2023, 02:43

I believe Steven meant do you have any other unique indexes? Currently any conflicts regarding indexes is treated the same as duplicate ID.

Nevus
14 Jul, 2023, 02:44

You should not need an unique index for id to resolve this issue.

mitsy0_0
14 Jul, 2023, 02:44

Oh yeah I have 4 unique indexes, including the one that I just created stupidly

Nevus
14 Jul, 2023, 02:45

There might be a conflict with those other 3 indexes.

mitsy0_0
14 Jul, 2023, 02:45

Oh? let me see

mitsy0_0
14 Jul, 2023, 08:34

It workedโœ…

mitsy0_0
14 Jul, 2023, 08:36

How does ID.unique() works? I couldn't find it in docs

Nevus
14 Jul, 2023, 08:37

For the SDK, it just returns "unique()" and the backend generates one for you.

Nevus
14 Jul, 2023, 08:37
Drake
14 Jul, 2023, 14:46

What was the problem?

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