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
643 stars 149 forks source link

Firestore Repeatedly Returning Error: 5 NOT_FOUND #2216

Open okwme opened 5 days ago

okwme commented 5 days ago

I found support for this issue from the firebase library but the issue exists in this library as well.

cloud.google.com/support told me this was "related to code and implementation" and "falls outside the scope of GCP tech support" even though I have the Enhanced Support for $500 / mo.

The issue is that if you're not using a database with the default name you have to explicitly declare the databaseID when instantiating the Firestore object. These docs never mention that or display an example of a database with a custom ID. The example given:

const {Firestore} = require('@google-cloud/firestore');

// Create a new client
const firestore = new Firestore();

async function quickstart() {
  // Obtain a document reference.
  const document = firestore.doc('posts/intro-to-firestore');

  // Enter new data into the document.
  await document.set({
    title: 'Welcome to Firestore',
    body: 'Hello World',
  });
  console.log('Entered new data into the document');

  // Update an existing document.
  await document.update({
    body: 'My first Firestore app',
  });
  console.log('Updated an existing document');

  // Read the document.
  const doc = await document.get();
  console.log('Read the document');

  // Delete the document.
  await document.delete();
  console.log('Deleted the document');
}
quickstart();

will fail unless the custom database ID is added explicitly as so:

const firestore = new Firestore({
    databaseId: 'custom-name'
});

it's probably best if you add the projectId there explicitly as well:

const firestore = new Firestore({
    projectId: 'my-project',
    databaseId: 'custom-name'
});

The error message for trying to write to the database without an explicit ID is unhelpful:

Error: 5 NOT_FOUND:
    at callErrorFromStatus (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/client.js:193:76)
    at Object.onReceiveStatus (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/client.js:161:32)
    at ServiceClientImpl.<anonymous> (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:237:29
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at repeat (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/normalCalls/retries.js:82:25)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/normalCalls/retries.js:125:13
    at OngoingCallPromise.call (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/google-gax/build/src/createApiCall.js:112:30
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Caused by: Error
    at _firestore._traceUtil.startActiveSpan (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/write-batch.js:438:27)
    at DisabledTraceUtil.startActiveSpan (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/telemetry/disabled-trace-util.js:16:16)
    at WriteBatch.commit (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/write-batch.js:436:43)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:354:31
    at DisabledTraceUtil.startActiveSpan (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/telemetry/disabled-trace-util.js:16:16)
    at DocumentReference.set (/Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:346:43)
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/index.js:35:49
    at /Users/billy/GitHub/trifle-labs/mmorps-gcp/functions/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:100:29
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  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'
}

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.

1) Is this a client library issue or a product issue? This is the client library for "@google-cloud/firestore" .

2) Did someone already solve this?

3) Do you have a support contract?

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

Steps to reproduce

  1. Make your first database with a custom name.
  2. write a doc to the collection as outlined above

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

tom-andersen commented 4 days ago

I will inform the maintainers of documentation that we should include a named database example. https://cloud.google.com/nodejs/docs/reference/firestore/latest/firestore/firestore#examples