Back

AppwriteException: document_already_exists, Document with the requested ID already exists. (409)

  • 0
  • Databases
  • Flutter
  • Cloud
Mosh Ontong
8 Aug, 2023, 18:54

Why I got this error I used this code:

TypeScript
  final id = ID.unique();
        _logger.info('Creating service overview for user $userId');
        response = await database.createDocument(
          databaseId: serviceCredential.databaseId,
          collectionId: serviceCredential.collectionId,
          documentId: id,
          data: data,
          permissions: [
            Permission.read(Role.any()),
            Permission.write(Role.user(userId)),
            Permission.update(Role.user(userId)),
            Permission.delete(Role.user(userId)),
          ],
        );

As you can see I used an ID unique but still I got document_already exist in my appwrite cloud . I just have only one document in my collection

TL;DR
The user is encountering a "document_already_exists" error in their Appwrite app when trying to create a new document. They have checked if there are any unique attributes, but the issue persists. The user shared their code which uses a unique ID. Solution: It is possible that there are other attributes in the document that need to be unique as well. It is recommended to check all the attribute values and ensure that they are unique. Additionally, users can try deleting the existing document before creating a new one to avoid the error.
Binyamin
8 Aug, 2023, 18:54

Maybe other attributes are unique?

Mosh Ontong
8 Aug, 2023, 18:54

But when I deleting the document it fix the error

Binyamin
8 Aug, 2023, 18:55

If for example the name is unquie And you're trying to insert another one with the same name

Binyamin
8 Aug, 2023, 18:55

You'll get that error

Mosh Ontong
8 Aug, 2023, 18:55

did you mean is the indexes?

Mosh Ontong
8 Aug, 2023, 18:55
Mosh Ontong
8 Aug, 2023, 18:55

I have this

Binyamin
8 Aug, 2023, 18:56

Yes Exactly

Binyamin
8 Aug, 2023, 18:56

Are the value of serverOwnerId is unqiue each time or same as the one already inserted

Mosh Ontong
8 Aug, 2023, 18:56

So I re create this index

Mosh Ontong
8 Aug, 2023, 18:57
Binyamin
8 Aug, 2023, 18:57

Yes

Mosh Ontong
8 Aug, 2023, 18:57

what should I choose?>

Mosh Ontong
8 Aug, 2023, 18:57

Key or FullText?

Binyamin
8 Aug, 2023, 18:57

Key will suit your use case

Mosh Ontong
8 Aug, 2023, 18:58

thank you I will try

Mosh Ontong
8 Aug, 2023, 18:59

Ohh it works thank youuu so much

Binyamin
8 Aug, 2023, 18:59

Except the cloud, after version 1.3.0 the key is not for allowing queries any more but to enhanced the filtering based on those 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