
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
- WebSocket reconnecting issues – Realtime...
Hello! I am experiencing a problem with the Realtime API. My frontend is constantly reconnecting to the WebSocket server, and as a result Realtime is not worki...
- dns issue with custom domain
im getting this, but i can access the appwrite through http://new.theasians.co.uk/console/ which is http but im not getting https, i deployed in vps through hos...
- Help needed on sites and funcions
I have Appwrite 1.7.4 self-hosted on a VPS. If I enable this parameter: `_APP_OPTIONS_ROUTER_FORCE_HTTPS` Functions work perfectly. If I disable it, the sites...
