Back

Query.equal() not working as expected? (Svelte,Typescript, Appwrite Cloud)

  • 0
  • Users
  • Databases
  • Web
  • Cloud
Chola
29 May, 2023, 07:38

I feel like I've overlooked something small, but it's now racking my brain, this code isn't returning what I need, which is documents belonging to just this one user who's signed in.

TypeScript
const userID = get(state).account!.$id;
const response = await sdk.database.listDocuments(server.database, server.collection, [Query.equal('ownerID',[userID]), Query.orderDesc('')]);
TL;DR
Users are discussing an issue with the `Query.equal()` method not working as expected in a Svelte and TypeScript project using the Appwrite Cloud service. One user suggests creating a team, adding users to it, and setting permissions on the team. Another user confirms that this solution worked for them. The original poster asks if they need to add the ID of another user to the permissions array of a document to give them permission to access it. A user explains that if document security is enabled, additional permission assignment is not necessary. The original poster asks if a regular call to get documents will automatically fetch only the ones they have permission for, without
Chola
29 May, 2023, 08:37

I have this import at the top of my page.

TypeScript
import { ID, Permission, Role, Query } from 'appwrite';

Not sure if i should be importing from node-appwrite instead?

Bouahaza
29 May, 2023, 08:38

node-appwrite is for backend

Bouahaza
29 May, 2023, 08:39

Give more information. Wich version of appwrite, cloud or locally, wich version of sdk, etc..

Bouahaza
29 May, 2023, 08:39

To got document of user, you need to set permission

Bouahaza
29 May, 2023, 08:39

And assign permission when you create document

Bouahaza
29 May, 2023, 08:39
Bouahaza
29 May, 2023, 08:41

And enable document security on collection

Chola
29 May, 2023, 08:44

I'll get you the versions of my environment shortly, the documents were created with the users permission, and I have document security enabled. Are you saying that a regular call to get the documents from the database will automatically fetch only the ones I have permission to? I don't need an additional Query filter?

Bouahaza
29 May, 2023, 08:52

You don't need if you enable document security yes

Bouahaza
29 May, 2023, 08:52

And connect via client sdk

Chola
29 May, 2023, 09:18

Great, that worked. For me to allow another user permission to the same document, i would have to add their ID to the permissions array of the document?

Bouahaza
29 May, 2023, 09:19

Yes

Bouahaza
29 May, 2023, 09:19

You can also make a teams, add your 2 users on it, and add permission on this team

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