Status Update
Comments
pa...@google.com <pa...@google.com>
pa...@google.com <pa...@google.com> #2
Hi,
Before setting a request, have you tried what the documentation says about ordering and limiting [1]? Here is another question related to your issue [2]. If these pages do not help you, could you please give us an example of what you want to achieve?
[1]
dm...@gmail.com <dm...@gmail.com> #3
Hi,
This is a problem with the query where clause. Ordering and limiting doesn't help.
Firestore supports a logical OR with '.where('cities', 'array-contains-any', ['Tokyo', 'Kyoto'])'. This results in documents that contain Tokyo or Kyoto in it's cities array.
Firestore does not support a logical AND such as '.where('cities', 'array-contains-all', ['Tokyo', 'Kyoto'])'. The result should be documents that contain Tokyo and Kyoto in it's cities array.
An example is as follows.
Data
{
"cities": ["Tokyo", "Kyoto", "Osaka", "Nara"],
"modified": 1645457445
}
{
"cities": ["Hakone", "Tokyo"],
"modified": 1645450245
}
{
"cities": ["Hiroshima", "Kyoto", "Tokyo"],
"modified": 1645453845
}
Query
db.collection("blogs")
.where("cities", "array-contains-all", ["Toyko", "Kyoto"])
.orderBy("modified", "desc")
.limit(10)
Expected result
{
"cities": ["Tokyo", "Kyoto", "Osaka", "Nara"],
"modified": 1645457445
}
{
"cities": ["Hiroshima", "Kyoto", "Tokyo"],
"modified": 1645453845
}
pa...@google.com <pa...@google.com> #4
Hi, thanks for your answer.
The Cloud Firestore engineering team is already aware of this request. There is no ETA for a resolution at this time, but all further updates should occur here.
sh...@gmail.com <sh...@gmail.com> #5
The query field in your example would be:
queries: ['Tokyo', 'Tokyo.Kyoto', 'Tokyo.Hiroshima', 'Tokyo.Kyoto.Hiroshima', 'Kyoto', 'Kyoto.Hiroshima', 'Hiroshima']
Then you can query your collection by 'array-contains' on this field. You could still add orderBy on a different to the index as well!
pi...@gmail.com <pi...@gmail.com> #6
Is there any update on the contains-all support? Logical AND will be greatly beneficial for the usability of firestore. We are trying to implement relatively complex filtering on a firestore collection(5+ properties, 3 of them are strings with 10-30 chars length), and if we try to put all possible combinations the size of the array basically explodes... another downside is, that this search array becomes part of the document themselves, and every time we fetch documents we need to transfer the huge search array...
regards,
pirin
fi...@gmail.com <fi...@gmail.com> #7
da...@shax.com <da...@shax.com> #8
I also need this, I am implementing a simple search with Firestore, searching for records that match one or more (normalised) keywords from a search query.
Currently my workaround is: if the query has one word, I use the keywords
array and sort the results as normal. However, if the query has two words, I also store a second copy of the keywords array as a dictionary in { keyword: true }
format, and use the dictionary to perform the query rather than the array. This has the downside that it's not possible to order the results (because it would require a compound index, and it is not be possible to include the dictionary of unknown keys in the compound).
In the long run I will probably use a third party search service like Algolia, but for now it is frustratingly difficult to implement a simple search on Firestore.
cn...@gmail.com <cn...@gmail.com> #9
ji...@gmail.com <ji...@gmail.com> #10
ge...@gmail.com <ge...@gmail.com> #11
va...@google.com <va...@google.com>
ku...@google.com <ku...@google.com>
ar...@gmail.com <ar...@gmail.com> #12
I would also love to know ETA or at least if this is gonna be implemented at all.
My scenarios involve adding roles with security rules and resources that are protected by a list of permissions that all must be met by a user.
Another scenario requires filtering of resources that are simultaneously shared between several users - in my case I need to show all resources that are shared with an admin (current user) that are also shared with specific clients (other users of the system)
I'm aware of workarounds (like creating an array of full index or reverting to an object), but the limitations there range from being very clunky to impossible at scale.
Any updates on the status of this feature are much appreciated.
je...@gmail.com <je...@gmail.com> #13
ed...@fpass.com.br <ed...@fpass.com.br> #14
mi...@gmail.com <mi...@gmail.com> #15
be...@gmail.com <be...@gmail.com> #16
ko...@gmail.com <ko...@gmail.com> #17
lo...@gmail.com <lo...@gmail.com> #18
gz...@gmail.com <gz...@gmail.com> #19
ch...@waitwhile.com <ch...@waitwhile.com> #20
Lack of array-contains-all makes our company consider migrating off Firestore.
Description
I have an app that allows people to create travel blogs and tag them with the cities that are the subject of the blog. I want users to view a feed of blogs (ordered by most recent) by specifying the cities they want to see blogs contain information about, for example Tokyo, Kyoto and Osaka. The data should be delivered in pages.
There is no support for a logical AND on an array field while also ordering by a timestamp and specifying a limit.
What you expected to happen:
A logical AND can be performed on an array field with order by and limit
Steps to reproduce:
* create a collection containing documents with an array and a timestamp
* attempt to query the collection to get results where the query array is a subset of the document's array, the results are ordered by timestamp and the results are limited for pagination
Other information (workarounds you have tried, documentation consulted, etc):
I have tried using maps instead of arrays as described here:
This doesn't work with order by
I also tried a reverse lookup as described by:
This also doesn't work with order by