Back

How to do query on `string array` attribute??

  • 0
  • Databases
steve jobs
14 May, 2023, 14:29

imagine i have an attribute named hashtags which is string array of hashtags (ie, like twitter hashtags),

in query, i have to get all the docs which have "hashtag1" or "hashtag2" in its hashtags colum.

how to implement it ??

TL;DR
The user is asking how to perform a query on a `string array` attribute in Appwrite. Currently, queries against arrays are not supported. However, there is a workaround where you can create a full-text index on the attribute and then use the search query. This workaround requires creating a full-text index on the attribute and using the search query. The user also mentions the absence of an "OR" option for search and wonders if only one keyword can be searched with a single query. The solution provided by another user suggests using `Query.equal(atrb, [...hastags])` to get all the documents that have either "has
otik
14 May, 2023, 16:02

I think that you can use Query.equal(atrb, [...hastags])

otik
14 May, 2023, 16:04

[hashtag1, hashtag2] means hashtag1 or hashtag2

steve jobs
14 May, 2023, 16:07

it does give empty result

Drake
14 May, 2023, 17:19

Queries against arrays are not supported at the moment. Make sure to πŸ‘ this issue: https://github.com/appwrite/appwrite/issues/2838

That said, there is a hack where you can create a full text index on the attribute and then use the search query.

steve jobs
14 May, 2023, 17:20

But in that hack, only 1 keyword can be searched with a single query right?

steve jobs
14 May, 2023, 17:20

There is no option to do "OR" on search.. right?

steve jobs
14 May, 2023, 17:23

And why is the custom query option not yet available? It would give developers more freedom i guess

Drake
14 May, 2023, 17:41

You can search space separated keywords.

Drake
14 May, 2023, 17:42

Because Appwrite is supposed to be an abstraction over the underlying database

steve jobs
15 May, 2023, 04:13

thankss.. that's what i needed

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