Back

Database collection only readable by admin Function

  • 0
  • Databases
  • Functions
  • Cloud
Quentin
26 Sep, 2024, 15:29

Hi there !

I'm trying to access a specific Document in a specific Collection within a Function. But the Function keeps crashing telling me the Document with the requested ID could not be found

I'm sure the document exist and the collection ID (and DB ID) are good.

The thing is, there is no permission on the Collection as I want this collection to be only accessible with the admin rights of the Funciton (no user can access it).

Here is the code I used

TypeScript
const adminClient = new Client()
        .setEndpoint(Bun.env['APPWRITE_FUNCTION_API_ENDPOINT'] as string)
        .setProject(Bun.env['APPWRITE_FUNCTION_PROJECT_ID'] as string)
        .setKey(Bun.env['x-appwrite-key'] as string);

const adminDatabase = new Databases(adminClient);

const prompt = await adminDatabase.getDocument(
        DB, 
        PROMPTS, 
        documentID, 
        [Query.select(['content'])]
);

Again, I am sure that documentID exists in PROMPTS...

Is there a specific permission to add in this case ? I'm a bit lost in this.

TL;DR
Developers are trying to access a specific document in a collection within a function but keep getting a "Document with requested ID could not be found" error. They want the collection to be admin-only. The issue might be related to missing permissions. Solution: They could add specific permissions for the admin to access the collection in the code.
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