I have this line:
firebase.firestore().collection('wishes').where(key, '==', userMeta[key]).where('expiration', '>', Date.now()).onSnapshot((querySnapshot) => {
[...]
}
If I remove the range filter, the query works as expected. If I keep the range filter, it will work only for the first read, then won't fire anymore when data is added. The expiration field is a timestamp and is being saved correctly in Firestore.
This is both iOS and Android, production and release build.
===
RNFirebase 3.2.0
react-native-cli: 2.0.1
react-native: 0.52.2
node 9.3.0
@DavideValdo have you checked the native logs to see whether there are any warnings about index creation?
This sounds very similar to https://github.com/invertase/react-native-firebase/issues/568 which we were unable to reproduce.
Tested with XCode console, no warning whatsoever
Two equality filters seem to work fine, I'll need to set the yetToExpire flag to false via Cloud Functions
firebase.firestore().collection('wishes').where('yetToExpire', '==', true).where(key, '==', userMeta[key]).onSnapshot((querySnapshot) => {
@DavideValdo I think this is probably worth taking up with Firebase directly. We can only report the information that's sent to us by the native SDK and it certainly seems like this is an issue there.
Are you able to report back on what they say?
This is their answer:
I see that you're using React Native. Unfortunately, we have limited support on troubleshooting with third-party libraries. I could only suggest that you ensure you are listening to the correct document, and note that the snapshot handler will only receive a new query snapshot every time the query results change (that is, when a document is added, removed, or modified).
Even though I've clearly stated that no index warning were generated on the native side, this is all I got...
Besides, such a query is documented in the official docs
citiesRef.where("state", "==", "CA").where("population", ">", 1000000)
[[citiesRef queryWhereField:@"state" isGreaterThanOrEqualTo:@"CA"]
queryWhereField:@"population" isGreaterThan:@1000000];
So maybe the best thing would be to add breakpoints somewhere where the Query object is being instantiated on the native? Kind of hard for me with little native knowledge
Thanks so far
@DavideValdo Have you seen the latest updates on the issue here: https://github.com/invertase/react-native-firebase/issues/568 ?
I wonder whether this is related in some way...
Hi guys,
anything new on this? Has anybody tried such a query on 4.x.x?
@chrisbianca So, I have tried the same query with the web sdk on React Native. I did get an error with a link to create a composite index, which I had created, but with fields in the wrong order:
This is the correct order, I had _expiration_ as the first field and it didn't work, but no warning was given by the native SDK at least on iOS.
So the original query is now working. I also got this error from the _JS_ SDK:
Is this something that you are aware of? Will it be the same for the native SDK as well, having specific types for the Firebase timestamp?
(The query started working after index was created, both with RNFirebase 3.x and 4.x so it's not a problem of the lib)
Thanks, can be closed
I have same issue. Combination of where('==').where('>') not working.
Firebase just added a handy document on how indexes in Firestore work: https://firebase.google.com/docs/firestore/query-data/index-overview. Particularly note the fact that composite indexes are not created automatically.
@DavideValdo I'm going to close this, as it seems like your initial issue has been resolved by the creation of the index.
The other error is something we're aware of, but currently the Android SDK doesn't have support for timestamps yet - as soon as it does, we'll be adding support to RNFirebase.
@zaizai123 did you get it to work by now? I have same issue at #1437
@zaizai123 I had that same issue. I fixed it by creating a composite index on the first and second fields of the 2 where clauses. For example, if your query is citiesRef.where("state", "==", "CA").where("population", ">", 1000000)
then you want a composite index of:
state _Ascending_ population _Ascending_
Most helpful comment
@zaizai123 I had that same issue. I fixed it by creating a composite index on the first and second fields of the 2 where clauses. For example, if your query is
citiesRef.where("state", "==", "CA").where("population", ">", 1000000)
then you want a composite index of: