appwrite: Bug : Query an Array attribute with an array of values does not work

๐Ÿ‘Ÿ Reproduction steps

I am trying to query a Collection where one attribute is an Array of string

Trying this syntax fails to retrieve anything (and it feels normal)

database.list_documents('collection',                                                                       
       [                                                                                                               
           Query.equal("array_attribute, ["value1","value2"])                             
       ]                                                                                                               
))

Trying this syntax fails also while it feels like it could work ๐Ÿ˜‰

database.list_documents('collection',                                                                       
       [                                                                                                               
           Query.equal("array_attribute, '["value1","value2"]')                             
       ]                                                                                                               
))

What I am trying to do is basically an โ€œArray IN Arrayโ€ comparison. Going the โ€œequalโ€ way seems hackish but I thought as the attribute is stored in a String it might work (and could be a work-around until a proprer โ€œinโ€ or โ€œcontainsโ€ operator exists. ?)

My only other option to make this work is use a function to โ€œexplodeโ€ the values contained in array_attribute in a new collection and then I can do a OR comparaison. It works but is not as straighforward + it generates a big collection.

๐Ÿ‘ Expected behavior

some content is being retrieved

๐Ÿ‘Ž Actual Behavior

Nothing is retrieved.

๐ŸŽฒ Appwrite version

Version 0.12.x

๐Ÿ’ป Operating system

Linux

๐Ÿงฑ Your Environment

No response

๐Ÿ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didnโ€™t find similar issue

๐Ÿข Have you read the Code of Conduct?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 24
  • Comments: 21 (3 by maintainers)

Most upvoted comments

I dont know if it is helpful, but i found out that you can use Query.search to looking for items in array.

This is not really supported as of right now, every possible solution will come with its downsides ๐Ÿ‘๐Ÿป

We are working on a way to query the contents of an array.

Is there any update on this issue ? Iโ€™m planing to have a tag search in an app so I search and found this thread.

@stnguyen90 I think making the single param called exact match make more sense as we can overloaded the function for partial matching. I propose sample use cases and syntax representation as follow.

  1. Partial matching (contains โ€˜aโ€™ or โ€˜bโ€™) - use case, tag filter where user may uncheck unwanted tags
[ Query.contains('tags', ['a'], ['b']) ]
  1. All matching (have both โ€˜aโ€™ and โ€˜bโ€™) - site admin query for counts or batch operation
[ Query.contains('tags', ['a', 'b']) ]
  1. All matching strictly (have both โ€˜aโ€™ and โ€˜bโ€™ and no others) - also site admin query
[ Query.arrayLength('tags', 2), Query.contains('tags', ['a', 'b']) ]
  1. Invert operation - if there are fewer unwanted tags, it would be more efficient to do the invert
[ Query.notContains('tags', ['a', 'b']) ]

Also, tag use case will need distinct query so we will know all available tag list before the query. I didnโ€™t see query distinct in the doc but it can be temporary fixed by having a unique list updated as each record created or updated. However, I think distinct query should be available for every attribute types.

@meepeek, @superseby2, for this type of functionality, are you expecting for documents to return if they have any least one of the values in the query? For example, letโ€™s say the document has ["flutter", "dart"] for attribute tags. Query.contains("tags", ["flutter", "react"]) would return the document because flutter is in the tags. Is this the functionality you need?