firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.62k stars 368 forks source link

[Firestore] Error: 5 NOT_FOUND when writing data #2623

Closed tobyL05 closed 2 months ago

tobyL05 commented 2 months ago

[READ] Step 1: Are you in the right place?

Cloud Firestore support is provided by the @google-cloud/firestore library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the nodejs-firestore GitHub repo.

If you still think the problem is related to the code in this repository, then read on.

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I cannot write any data to an empty Cloud Firestore using the Firebase Admin SDK. Trying to write any data results in the following error. The code to write to firestore is located in a POST request endpoint using express.js (4.19.2)

Firestore (7.9.0) 2024-07-09T20:48:58.486Z gmAhV [WriteBatch.commit]: Sending 1 writes
Firestore (7.9.0) 2024-07-09T20:48:58.490Z gmAhV [ClientPool.acquire]: Creating a new client (requiresGrpc: false)
Firestore (7.9.0) 2024-07-09T20:48:58.563Z ##### [clientFactory]: Initialized Firestore GAPIC Client (useFallback: false)
Firestore (7.9.0) 2024-07-09T20:48:58.563Z gmAhV [Firestore.request]: Sending request: {"database":"projects/ubc-pmc-portal/databases/(default)","writes":[{"update":{"name":"projects/ubc-pmc-portal/databases/(default)/documents/users/alovelace","fields":{"first":{"stringValue":"Ada"},"last":{"stringValue":"Lovelace"},"born":{"integerValue":1815}}}}]}
Firestore (7.9.0) 2024-07-09T20:48:58.762Z gmAhV [Firestore.request]: Received error: Error: 5 NOT_FOUND: 
    at callErrorFromStatus (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/call.ts:82:17)
    at Object.onReceiveStatus (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/client.ts:360:55)
    at Object.onReceiveStatus (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/client-interceptors.ts:458:34)
    at Object.onReceiveStatus (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/client-interceptors.ts:419:48)
    at /Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/resolving-call.ts:163:24
    at processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/client.ts:325:42)
    at ServiceClientImpl.<anonymous> (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@grpc/grpc-js/src/make-client.ts:189:15)
    at /Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:237:29
    at /Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at repeat (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/normalCalls/retries.js:80:25)
    at /Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/normalCalls/retries.js:119:13
    at OngoingCallPromise.call (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /Users/tobs/Desktop/code/PMC/pmc-portal-be/node_modules/google-gax/build/src/createApiCall.js:112:30
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 5,
  details: '',
  metadata: Metadata {
    internalRepr: Map(1) { 'x-debug-tracking-id' => [Array] },
    options: {}
  },
  note: 'Exception occurred in retry method that was not classified as transient'
}

Relevant Code:

credentials JSON looks like this:

{
  "type": "",
  "project_id": "",
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": "",
  "universe_domain": ""
}

Firebase config:

import { cert, initializeApp, ServiceAccount } from "firebase-admin/app";
import serviceAccount from "../../.secret/pmc-portal-credential.json";
import { Auth, getAuth } from "firebase-admin/auth";
import { Firestore, getFirestore } from "firebase-admin/firestore";
import { firestore } from "firebase-admin";

initializeApp({
  credential: cert(serviceAccount as ServiceAccount),
});

const auth: Auth = getAuth()
const db: Firestore = getFirestore();

firestore.setLogFunction(console.log)

export { auth, db }

Adding data to firestore

import { db } from "../../config/firebase";

const docRef = db.collection('users').doc('alovelace');

await docRef.set({
    first: 'Ada',
    last: 'Lovelace',
    born: 1815
});
google-oss-bot commented 2 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.