Closed oscarthroedsson closed 1 month ago
Thanks for reporting @oscarthroedsson . I'll try to reproduce the issue
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.
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);
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] } } }
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 } } }
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); });
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'
}