Back

Appwrite Custom ID

  • 0
  • General
  • Flutter
hamed
11 May, 2023, 20:42

Hey there, out of curiosity, what is the difference between passing ID.custom(id) to a document ID instead of a custom string variable? I mean, if I'm going to call this function and pass my custom ID to it, couldn't I just pass my custom ID directly? It doesn't make any sense to me

TL;DR
The user is asking about the difference between using ID.custom(id) and a custom string variable as the document ID in an app called Appwrite. They believe that using ID.custom(id) doesn't make sense and that they could simply pass their custom ID directly. The solution is to explain that ID.custom(id) is used to explicitly indicate that the ID being passed is a custom ID, while using a custom string variable may not be as clear.
Binyamin
11 May, 2023, 20:43

Yoy mean when creating document

hamed
11 May, 2023, 20:43

Yes,

Binyamin
11 May, 2023, 20:44

👍

Binyamin
11 May, 2023, 20:44

And you mean ID.unique() Function?

hamed
11 May, 2023, 20:45

No, just 'ID.custom(id)'

Binyamin
11 May, 2023, 20:45

Can you share the code?

Binyamin
11 May, 2023, 20:47

Why are you using the ID.custom

hamed
11 May, 2023, 20:50
TypeScript
const String documentID = 'mycustomID';

      await ApiConst.databases.createDocument(
        databaseId: ApiConst.databaseID,
        collectionId: collectionsIDs[type]!,
        documentId: ID.custom(documentID),
        permissions: permissions,
        data: data,
      );
hamed
11 May, 2023, 20:50
TypeScript
const String documentID = 'mycustomID';

      await ApiConst.databases.createDocument(
        databaseId: ApiConst.databaseID,
        collectionId: collectionsIDs[type]!,
        documentId: documentID,
        permissions: permissions,
        data: data,
      );
Binyamin
11 May, 2023, 21:01

From you can see from the code it doesn't make any different and both ways will work the same

You can see here https://github.com/appwrite/sdk-for-flutter/blob/master/lib/id.dart#L10

hamed
11 May, 2023, 21:02

Sometimes I need to assign the same ID to multiple documents stored in different collections (belonging to a particular user). This helps me retrieve these documents easily when needed without having to create any indexes

hamed
11 May, 2023, 21:04

Okay,

Binyamin
11 May, 2023, 21:09

You can just send any string as the id

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