Back

Query Problem

  • 0
  • Databases
  • Web
  • Cloud
LAKSHYA
9 Feb, 2024, 10:03

i have an attribute called tags which is an array contains ["ForAbsoluteBegginers","superman", "batman", "Iron man"] inside the upload collection. now i wanted to only the the document if tags contains ForAbsoluteBegginers otherwise do not want. this is my code.

async CategoryBegginersInfo(Cateogry:string) { try { return await this.databases.listDocuments( conf.appwriteDatabaseId, conf.appwriteCollectionId, [ Query.equal("category", Cateogry), Query.equal("tags", ["ForAbsoluteBegginers"]), Query.equal("status", "Approved") // Add this condition ] ); } catch (error) { console.error("appwrite service :: CategoryBegginersInfo :: ", error); return false; } }

but it is returning me the empty document the only problem is with this line Query.equal("tags", ["ForAbsoluteBegginers"]), how to get only those document which tags includes ForAbsoluteBegginers

TL;DR
Developers are experiencing issues with a query in their code. They have an "upload" collection with an attribute called "tags," which is an array of values. They want to only retrieve documents where the "tags" array contains the value "ForAbsoluteBegginers." However, their current code is not returning any documents, and they suspect the issue lies with the line: `Query.equal("tags", ["ForAbsoluteBegginers"])`. Solution: The developer needs to use the `Query.contains()` function instead of `Query.equal()` to check if the "tags" array contains the desired value. They should modify the
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