
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
- Collection Permission issue
I am facing issue in my Pro account. "Add" button is disabled while adding permission in DB collection settings.
- Origin error after changing default port...
Hi! I need some help regarding an issue I’m facing with Appwrite after changing the default ports. I have a self-hosted Appwrite instance running on my VPS. I ...
- Opened my website after long time and Ba...
I built a website around a year back and and used appwrite for making the backend. At that time the website was working fine but now when i open it the images a...
