Back

node-appwrite Query filters

  • 0
  • Cloud
tnn
14 Mar, 2024, 10:27

Hi, i can't manage to use listDocuments with node-appwrite. Documentation invites me to use Query.equal, but an error throws for invalid query. copilot insists that i use just array of strings, but all tries become invalid query errors.

what's is the right way to search in documents with node-appwrite 12 ?

here's my code :

TypeScript
      const filters = [
        `guildId==${guildId.toString()}`,
        `slug=='${slug}'`
      ];
    
      const giveaways = await databases.listDocuments(
        appWriteConfig.databaseId, 
        appWriteConfig.giveawayCollection, 
        filters);
TypeScript
    throw new Error(error.message);
          ^

Error: Invalid query: guildId==1205061903601369118

many thanks !

TL;DR
Developers are encountering issues with query filters in node-appwrite. The correct way to search in documents is to use Query.equal, not strings. Instead, follow appwrite's documentation and use Query.equal method for filters. Update the code to: ``` const filters = [ Query.equal('guildId', guildId.toString()), Query.equal('slug', slug) ]; const giveaways = await databases.listDocuments( appWriteConfig.databaseId, appWriteConfig.giveawayCollection, filters); ``` This should resolve the invalid query errors and enable successful document searching.
tnn
14 Mar, 2024, 10:35

if i write :

TypeScript
      const filters = [
        Query.equal('guildId', guildId.toString()),
        Query.equal('slug', slug)
      ];
  

          const giveaways = await databases.listDocuments(
            appWriteConfig.databaseId, 
            appWriteConfig.giveawayCollection, 
            filters);

i obtain : throw new Error(error.message); ^

Error: Invalid query: {"method":"equal","attribute":"guildId","values":["1205061903601369118"]} at Giveaway.retrieve (giveaway.js:69:15)

tnn
14 Mar, 2024, 10:37
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