On version 1.3.7
The context: collection A has a many to many relationship with collection B.
Using Server API, we can create documents in A with the "child-documents" of B in the same call provided the "child document" in the call does not already exist in collection B. You can provide the $id of the child-documents in the same call to create a document in A.
However, if a document - say, with $id = 'abc' - already exists in B, a call to create a document in A along with child-document of B with { $id: 'abc' } will cause a super-cryptic error:
[Error] Timestamp: 2024-03-18T16:28:05+00:00
[Error] Method: POST
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: Appwrite\Extend\Exception
[Error] Message: The current user is not authorized to perform the requested action.
[Error] File: /usr/src/code/app/controllers/api/databases.php
[Error] Line: 2726
I almost thought I hit into database corruption again... which I'm trying to climb out of.
After investigation, the answer is that if the child-document already exists in collection B, then you can only "link" e.g. [ <doc ID a>, { $id: def}] where def has not been created but doc ID a is already in collection B.
I'm not sure what is the behavior in the later versions but I was expecting that if the call to createDocument along with those details, Appwrite should update if the same document ID can be be found in the "child collection". Even if not, I think the error was unexpected - hence the cryptic "current user is not authorized" error.
Recommended threads
- Error When load the website
Hi, I am getting this error whenever I reload my website please help me, I am using react Error: ** GET https://cloud.appwrite.io/v1/account 401 (Unauthoriz...
- Migrate from cloud to localhost
Hello everyone. I need to migrate my test project from cloud to localhost, however it seems that this is possible only if a self-hosted appwrite instance it's h...
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?