googleapis / nodejs-firestore

Node.js client for Google Cloud Firestore: a NoSQL document database built for automatic scaling, high performance, and ease of application development.
https://cloud.google.com/firestore/
Apache License 2.0
642 stars 150 forks source link

Get: 5 NOT FOUND (node.js) #2202

Closed oscarthroedsson closed 1 month ago

oscarthroedsson commented 1 month ago

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

I Create my projects on firebase.

admin.initializeApp({ credential: admin.credential.cert(serviceAccountKey as admin.ServiceAccount), });

const db = admin.firestore();

const userRef = db .collection("users") .add({ firstName: "John", lastName: "Doe", email: "john.doe@example.com", }) .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) .catch((error) => { console.error("Error adding document: ", error); });

console.log("db: ", db); export const usersCollection = db.collection("users"); console.log("usersCollection: ", usersCollection);

- I generate a private key on firebase and add it to the directory
- I console.log everything and I can see my DB, collection and min private key
**DB**

db: Firestore { _settings: { credentials: { private_key: "key in string-format" client_email: 'firebase-adminsdk-xf1zi@sanitashealthapp.iam.gserviceaccount.com' }, projectId: 'sanitashealthapp', firebaseVersion: '12.5.0', preferRest: undefined, databaseId: '(default)', libName: 'gccl', libVersion: '7.10.0 fire/12.5.0', toJSON: [Function (anonymous)] }, _settingsFrozen: true, _serializer: Serializer { createReference: [Function (anonymous)], createInteger: [Function (anonymous)], allowUndefined: false }, _projectId: 'sanitashealthapp', _databaseId: '(default)', registeredListenersCount: 0, bulkWritersCount: 0, _traceUtil: DisabledTraceUtil {}, _backoffSettings: { initialDelayMs: 100, maxDelayMs: 60000, backoffFactor: 1.3 }, _clientPool: ClientPool { concurrentOperationLimit: 100, maxIdleClients: 1, clientFactory: [Function (anonymous)], clientDestructor: [Function (anonymous)], grpcEnabled: false, activeClients: Map(0) {}, failedClients: Set(0) {}, terminated: false, terminateDeferred: Deferred { resolve: [Function (anonymous)], reject: [Function (anonymous)], promise: [Promise] } } }

**Collection:**

usersCollection: CollectionReference { _firestore: Firestore { _settings: { credentials: [Object], projectId: 'sanitashealthapp', firebaseVersion: '12.5.0', preferRest: undefined, databaseId: '(default)', libName: 'gccl', libVersion: '7.10.0 fire/12.5.0', toJSON: [Function (anonymous)] }, _settingsFrozen: true, _serializer: Serializer { createReference: [Function (anonymous)], createInteger: [Function (anonymous)], allowUndefined: false }, _projectId: 'sanitashealthapp', _databaseId: '(default)', registeredListenersCount: 0, bulkWritersCount: 0, _traceUtil: DisabledTraceUtil {}, _backoffSettings: { initialDelayMs: 100, maxDelayMs: 60000, backoffFactor: 1.3 }, _clientPool: ClientPool { concurrentOperationLimit: 100, maxIdleClients: 1, clientFactory: [Function (anonymous)], clientDestructor: [Function (anonymous)], grpcEnabled: false, activeClients: Map(0) {}, failedClients: Set(0) {}, terminated: false, terminateDeferred: [Deferred] } }, _queryOptions: QueryOptions { parentPath: ResourcePath { segments: [] }, collectionId: 'users', converter: { toFirestore: [Function: toFirestore], fromFirestore: [Function: fromFirestore] }, allDescendants: false, filters: [], fieldOrders: [], startAt: undefined, endAt: undefined, limit: undefined, limitType: undefined, offset: undefined, projection: undefined, kindless: false, requireConsistency: true }, _serializer: Serializer { createReference: [Function (anonymous)], createInteger: [Function (anonymous)], allowUndefined: false }, _allowUndefined: false, _queryUtil: QueryUtil { _firestore: Firestore { _settings: [Object], _settingsFrozen: true, _serializer: [Serializer], _projectId: 'sanitashealthapp', _databaseId: '(default)', registeredListenersCount: 0, bulkWritersCount: 0, _traceUtil: DisabledTraceUtil {}, _backoffSettings: [Object], _clientPool: [ClientPool] }, _queryOptions: QueryOptions { parentPath: [ResourcePath], collectionId: 'users', converter: [Object], allDescendants: false, filters: [], fieldOrders: [], startAt: undefined, endAt: undefined, limit: undefined, limitType: undefined, offset: undefined, projection: undefined, kindless: false, requireConsistency: true }, _serializer: Serializer { createReference: [Function (anonymous)], createInteger: [Function (anonymous)], allowUndefined: false } } }

But when I try to add a doc with this code:

const userRef = db .collection("users") .add({ firstName: "John", lastName: "Doe", email: "john.doe@example.com", }) .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) .catch((error) => { console.error("Error adding document: ", error); });

I get this error msg:

Error adding document: Error: 5 NOT_FOUND: at callErrorFromStatus (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/call.ts:82:17) at Object.onReceiveStatus (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/client.ts:360:55) at Object.onReceiveStatus (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/client-interceptors.ts:458:34) at Object.onReceiveStatus (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/client-interceptors.ts:419:48) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/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/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/client.ts:325:42) at ServiceClientImpl. (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@grpc/grpc-js/src/make-client.ts:189:15) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:237:29 at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16 at repeat (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/normalCalls/retries.js:82:25) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/normalCalls/retries.js:125:13 at OngoingCallPromise.call (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/call.js:67:27) at NormalApiCaller.call (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/google-gax/build/src/createApiCall.js:112:30 at processTicksAndRejections (node:internal/process/task_queues:95:5) Caused by: Error at _firestore._traceUtil.startActiveSpan (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/write-batch.js:438:27) at DisabledTraceUtil.startActiveSpan (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/telemetry/disabled-trace-util.js:16:16) at WriteBatch.commit (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/write-batch.js:436:43) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:277:18 at DisabledTraceUtil.startActiveSpan (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/telemetry/disabled-trace-util.js:16:16) at DocumentReference.create (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:273:43) at /Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/reference/collection-reference.js:221:32 at DisabledTraceUtil.startActiveSpan (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/telemetry/disabled-trace-util.js:16:16) at CollectionReference.add (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/node_modules/@google-cloud/firestore/build/src/reference/collection-reference.js:216:43) at Object. (/Users/oscarthroedsson/Code/MyOwnProjects/mealplaner/server/Config/firebase.ts:12:4) { 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' }



I have a hard time navigate threw googles documentation but I have tried my hardest. But can´t figure out why this isn´ t working.  
ehsannas commented 1 month ago

Thanks for reporting @oscarthroedsson . I'll try to reproduce the issue

ehsannas commented 1 month ago

Hey @oscarthroedsson , I'm not able to reproduce the issue using your code -- with the exception that I use admin.initializeApp();

My only two comments are: 1- The const userRef = db........ code snippet returns a Promise, so make sure you await it. 2- There may be something wrong with the way you're authenticating. Please follow the instructions here: https://firebase.google.com/docs/admin/setup#add-sdk.