-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 Error "firestore/failed-precondition" when filtering a collection group query in FireStore #3737
Comments
I figured out the problem. My mistake was apparently in having made a "Composite" index (as I mentioned in the question) as it was the opening page on clicking "Indexes". I should have made a "Single field" index: After deleting my existing composite index, I made a new "single field" index with details as: Click 'Next' and on the next screen, "enable" one of the options under 'Collection group scope' (I chose Ascending): It is important to do the above, or else the query will not work. And then everything worked as expected, with my original code:
Note: If you happen to delete a particular "index", it takes some time (upto 10 minutes on some occasions) to be ready. During this period you will get an error if trying to create an index for the same entry. So wait, and try again after some time. |
@appukuttan-shailesh thanks for documenting this, I was questioning my sanity. I trusted the "Just run the query and click the URL if one pops up" advice rather than creating my Collection Group Queries up front weeks ago. Now I've burned half a day finally realizing that the reason the query was throwing an error was the missing index, but like you, no URL was in the message, just the error. |
If you put your query in a Try/Catch you will not get the link. Just simple "failed-precondition". |
The You can get the link to create the index by using the third argument to print the error in the console. An example:
|
I also don't get the link, either by catching the exception or just letting it be unhandled. It was only experience with that type of error that led me to realise that I needed to add an index. Where is the normally helpful error message with he create index link in it for this case? |
I just had the same issue. What I've actually tried to do:
What the issue actually mean:
Note that if you may filter by different fields (sets of fields) you need to make sure you have indexes for all of them. |
If you run it the app with the query that is missing an index on an android device or emulator and are running |
@mikehardy Actually I received an URL to create an index... but only a composite one. I got no links regards adding "single field" indexes, just a |
Interesting - I've seen the same with cloud functions - that's something you might file upstream with the firebase official site as cloud functions aren't under our control at all and if there is a missing index it would be good to know, composite or single index, yes. The firebase-tools local emulator never appears to care about indexes so I don't find out about them myself until I deploy to my dev or qa backends |
We have also started to run into an issue where we get a |
That's a known issue, follow this thread for updates: googleapis/nodejs-firestore#1866 (Adding this here because it's one of the top Google search results, so more people are likely to come across this thread) |
Issue
I have a database structure as follows (simplified for purposes of this question):
I am using a collection group query to retrieve all the orders under "item_A" (across all users). I am able to get this to work via:
But now I need to refine the above to be able to filter for orders from specific cities (e.g. Paris). So I tried adding a 'where' clause as follows:
But this fails, and I get the following message:
I have already set up a composite index on my FireStore database with the following details:
I am not sure what I am doing incorrectly. I wondered if the problem is with using an object property within the 'where' clause (which should not be a problem I believe). So I also tested with a simpler query such as:
But this too failed. What am I doing wrong?
I tried to find the "link" to create the composite index directly via error message but I just cannot locate this in my logs.
I tried the following (based on discussion here):
But in both these places I simply find the same error message I mentioned earlier.
I can find nothing with the tag
RNFSCollectionReference
or anything else that helps.On doing
adb logcat -s RNFSCollectionReference
I simply get (as mentioned by @tiendn here):Project Files
Javascript
Click To Expand
package.json
:"react": "16.11.0",
"react-native": "0.62.2",
"@react-native-firebase/app": "^7.0.1",
"@react-native-firebase/auth": "^6.7.1",
"@react-native-firebase/firestore": "^7.0.1",
# N/A
firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:"@react-native-firebase/app": "^7.0.1",
"@react-native-firebase/auth": "^6.7.1",
"@react-native-firebase/firestore": "^7.0.1",
Firebase
module(s) you're using that has the issue:e.g. Instance ID
TypeScript
?N
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: