0

I am trying to write to firestore database, but no success.

I am using firebase-admin version 11.3.0

I can read and write into firebase realtime database, but I can only read documents from firestore.

The nextJS API function is as below. As can be seen, I am trying to write 1 document with just a timestamp field.

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {

  const timestamp = Date.now()

  const result = await admin.firestore().collection("Test").doc("doctest").set({timestamp: timestamp})

  console.log("AWAIT: ", result.data())
  return res.status(500).end()

}

The error I am getting is below:

error - Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
    at Object.callErrorFromStatus (/home/node/app/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/home/node/app/node_modules/@grpc/grpc-js/build/src/client.js:195:52)
    at Object.onReceiveStatus (/home/node/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
    at Object.onReceiveStatus (/home/node/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
    at /home/node/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:188:78
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/home/node/app/node_modules/@grpc/grpc-js/build/src/client.js:163:34)
    at ServiceClientImpl.<anonymous> (/home/node/app/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /home/node/app/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:225:29
    at /home/node/app/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
    at repeat (/home/node/app/node_modules/google-gax/build/src/normalCalls/retries.js:80:25)
    at /home/node/app/node_modules/google-gax/build/src/normalCalls/retries.js:118:13
    at OngoingCallPromise.call (/home/node/app/node_modules/google-gax/build/src/call.js:67:27)
    at NormalApiCaller.call (/home/node/app/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
    at /home/node/app/node_modules/google-gax/build/src/createApiCall.js:84:30
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Caused by: Error
    at WriteBatch.commit (/home/node/app/node_modules/@google-cloud/firestore/build/src/write-batch.js:433:23)
    at DocumentReference.set (/home/node/app/node_modules/@google-cloud/firestore/build/src/reference.js:391:27)
    at handler (webpack-internal:///(api)/./pages/api/store/[storeid]/department/[depid]/product/[prodid].ts:51:132)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.apiResolver (/home/node/app/node_modules/next/dist/server/api-utils/node.js:367:9)
    at async DevServer.runApi (/home/node/app/node_modules/next/dist/server/next-server.js:476:9)
    at async Object.fn (/home/node/app/node_modules/next/dist/server/next-server.js:738:37)
    at async Router.execute (/home/node/app/node_modules/next/dist/server/router.js:252:36)
    at async DevServer.run (/home/node/app/node_modules/next/dist/server/base-server.js:381:29)
    at async DevServer.run (/home/node/app/node_modules/next/dist/server/dev/next-dev-server.js:732:20) {
  code: 4,
  details: 'Deadline exceeded',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient',
  page: '/api/store/[storeid]/department/[depid]/product/[prodid]'
}

I haven't exceeded the limits of read and write. Actually, I have used less than 1% of read and write quota.

I could not say for sure that is the poor internet connection, because I can read and write into firebase realtime database. In addition, I can read documents from firestore.

How to overcome this issue?

Aliton Oliveira
  • 1,224
  • 1
  • 15
  • 26
  • Have you done a web search for "firestore deadline exceeded"? It's not about total read and write quota. It's about the rate at which you write a single document. https://github.com/firebase/firebase-admin-node/issues/1396 – Doug Stevenson Jan 14 '23 at 03:19
  • I cannot understand it. Is the rate too much? 1 doc with 1 field is impacting the rate at which I write? – Aliton Oliveira Jan 14 '23 at 03:25
  • Yes! I already read all the links and the limit or quota is the closest answer given by the users. They are trying to batch lots of documents while I am trying to write 1 field in 1 document. – Aliton Oliveira Jan 14 '23 at 03:34
  • It doesn't matter how many fields you update. It matters how many times you update a single document over a period of time. We can't really see all the details of what you're doing. If you have additional information on how someone can reproduce this behavior using *minimal isolated code and documents*, please edit the question to share that, or ask an entirely new question. Consistent reproduction steps are required for help on Stack Overflow. – Doug Stevenson Jan 14 '23 at 04:42
  • I am the only one trying to write into the firestore dabase. The errors disappeared after restarting the nextJS server. – Aliton Oliveira Jan 16 '23 at 13:31

0 Answers0