Back

[SOLVED] ID.unique() use in attributes

  • 0
  • Web
jekalat
12 May, 2023, 07:03

Hi all! Can I use ID.unique() for attributes? it returns a string “unique()”, not a unique code Thank you!

TL;DR
The user was asking if they can use `ID.unique()` for attributes in their code. Another user provided a link to the code that generates the ID in Appwrite and clarified that `ID.unique()` returns only the string "unique()", not a unique code. They also mentioned that the generation of the unique ID happens inside Appwrite on the server. The solution provided is to use the `ID.unique()` method that comes with the Appwrite SDK to generate a string of unique and random characters for the documentId when creating a new document with `databases.createDocument()`.
safwan
12 May, 2023, 07:10

Can you provide some more details?

  1. What SDK are you using?
  2. What's your Appwrite version? Is it on cloud or sel-hosted?
safwan
12 May, 2023, 07:13

Without any of this info, all I can say is that if you are creating a new document with databases.createDocument(), you can use the ID.unique() method that comes with the Appwrite SDK to generate a string of unique and random characters for the documentId

jekalat
12 May, 2023, 07:27

@safwan hi, thank you for answer.

  1. web sdk (client)
  2. 1.3 cloud (aws instance) example: const role_id = ID.unique(); try { let response = await database.createDocument(db_id, db_roles_id, 'unique()', {'role_id':role_id,'role_name':role_name}); …..
safwan
12 May, 2023, 07:42

If i'm not wrong, you have to use ID.unique() for the web sdk

Binyamin
12 May, 2023, 07:59

The function ID.unqiue() returns only the string
The generation of the unique id generation happens inside Appwrite in the server

Binyamin
12 May, 2023, 08:04

You can look here for the actual code that generates the ID in Appwrite

https://github.com/utopia-php/database/blob/main/src/Database/Helpers/ID.php#L12

jekalat
12 May, 2023, 08:37

@Binyamin thank you for answer!

jekalat
12 May, 2023, 08:41

[SOLVED] ID.unique() use in attributes

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