nodejs-firestore: Error getting documents: Error: 9 FAILED_PRECONDITION when using collectionGroup
Environment details
- OS: 13.2.1 (22D68)
- Node.js version: v18.15.0
- npm version: v9.5.0
@google-cloud/firestoreversion: I was told to come to this repo to get the responses quickly, although I’m using firestore-admin 11.9.0
Steps to reproduce
- Use any collectionGroup and call get function
db.collectionGroup("textTemplates")
.where("id", "==", templateId)
.get()
- You’ll receive an error:
Google API requested!
- URL: "https://oauth2.googleapis.com/token"
- Be careful, this may be a production service.
> Error getting documents: Error: 9 FAILED_PRECONDITION:
> at callErrorFromStatus (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
> at Object.onReceiveStatus (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/client.js:357:73)
> at Object.onReceiveStatus (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
> at /Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
> at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
> for call at
> at ServiceClientImpl.makeServerStreamRequest (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/client.js:340:32)
> at ServiceClientImpl.<anonymous> (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
> at /Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:227:29
> at /Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/streamingCalls/streamingApiCaller.js:38:28
> at /Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
> at Object.request (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/streamingCalls/streaming.js:130:40)
> at makeRequest (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/retry-request/index.js:141:28)
> at retryRequest (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/retry-request/index.js:109:5)
> at StreamProxy.setStream (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/streamingCalls/streaming.js:121:37)
> at StreamingApiCaller.call (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/node_modules/google-gax/build/src/streamingCalls/streamingApiCaller.js:54:16)
> Caused by: Error
> at Query._get (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/build/src/reference.js:1717:23)
> at Query.get (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/@google-cloud/firestore/build/src/reference.js:1705:21)
> at startTextSequencesHandler (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/lib/functions/callable/start-text-sequences.js:25:10)
> at fixedLen (/Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/firebase-functions/lib/v2/providers/https.js:118:31)
> at /Users/dumitrucucu/Desktop/VRSEN/admagic-ai/back/functions/node_modules/firebase-functions/lib/common/providers/https.js:467:32
> at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
> at async runFunction (/Users/dumitrucucu/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:506:9)
> at async runHTTPS (/Users/dumitrucucu/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:5)
> at async /Users/dumitrucucu/.nvm/versions/node/v18.15.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:693:21 {
> code: 9,
> details: '',
> metadata: Metadata { internalRepr: Map(0) {}, options: {} }
> }
I created the necessary indexes on Firestore Console:
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 22 (6 by maintainers)
Hey guys,
I found an alternative solution to fix this problem. Here are the steps:
Go to Firestore
Click on Query builder tab
Replicate the same query through UI:
That’s it. You get the index link in console.
This is absolutely ridiculous, you can’t warn us when developing and you ‘don’t know why the text is stripped from the error’, so we can’t even set up a proper alert in case a missing index gets through to production. Come on Google, do better.
My firebase-admin: ^11.10.1
Same problem running this code snippet in a deployed code:
Error in GCP:
It really seems that the link to create the indexes should come, but it’s just showing a generic error
I think that the main issue here is that the FAILED_PRECONDITION error is not including create query index -link.
I found the issue. All I had to do is to use
orderBy, and after that I received an index link for firestore console.I want to add to this thread. The solution I found for this was as simple (not so simple if you don’t know) as going to the console query builder and executing the query I wanted to execute. In terms of running it on the collectionGroup, it will not execute but will give you the link to setup the indexes you are missing.
Agree. I’m having the same issue today and the error log is not helpful.
Running into this also. As an alternative to running the query locally, I was able to get the index creation link by using the GCP Console with the Query Builder. But even if the link wasn’t generated via that method, it does allow you to quickly test if a particular query would be supported, and then manually go through the process of adding the index in the GCP Console.
Thank you for this additional information. @tom-andersen will follow up early next week.