
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
- Looking for Partner
I'm looking for a partner for long-term collaboration. Of course, you'll get paid for it. If you are interested, please send a DM to me
- Having errors migrating to cloud
Project will not migrate compeltely
- ENV vars not updating
When i do `nano .env` it shows `_APP_DOMAIN_TARGET=` as set to my domain, but when i do `docker compose exec appwrite vars` it shows `_APP_DOMAIN_TARGET=` as ...
